Skip to content

Conversation

@CyberAP
Copy link
Contributor

@CyberAP CyberAP commented Apr 1, 2025

This change makes it possible to unstub actions when using stubActions: true in createTestingPinia. To do that you have to call mockRestore on the action.

createTestingPinia()

useMyStore().someAction.mockRestore()

// this calls an actual implementation
useMyStore().someAction()

The support for unstubbing is provided only for jest and vitest.

@netlify
Copy link

netlify bot commented Apr 1, 2025

Deploy Preview for pinia-official ready!

Name Link
🔨 Latest commit e4a37d0
🔍 Latest deploy log https://app.netlify.com/sites/pinia-official/deploys/67eba452886531000841b72b
😎 Deploy Preview https://deploy-preview-2960--pinia-official.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-project-automation github-project-automation bot moved this to 🆕 Triaging in Pinia Roadmap Jun 3, 2025
@posva posva moved this from 🆕 Triaging to 💬 In discussion in Pinia Roadmap Jun 3, 2025
@posva posva moved this from 💬 In discussion to 🧑‍💻 In progress in Pinia Roadmap Jun 3, 2025
@lostncg
Copy link

lostncg commented Aug 12, 2025

This feature is useful, may I know when it gonna release? @posva

@posva
Copy link
Member

posva commented Nov 3, 2025

Thanks a lot for this! I'm reworking

The approach you want should already be doable with type support using the helper mentioned in docs. It depends on your testing framework

@posva posva closed this Nov 3, 2025
@github-project-automation github-project-automation bot moved this from 🧑‍💻 In progress to ✅ Done in Pinia Roadmap Nov 3, 2025
@CyberAP
Copy link
Contributor Author

CyberAP commented Nov 3, 2025

@posva this is somewhat different. We could stub specific actions before that:

createTestingPinia({ stubActions: false })
actionsToStub.forEach(action => jest.spyOn(useMyStore(), action).mockReturnValue())

What we can't do is stub everything but unstub specific actions.

posva added a commit that referenced this pull request Nov 3, 2025
@posva
Copy link
Member

posva commented Nov 3, 2025

You can unstub specific actions, I just tested it. But now you can also pass a function to stubActions and return a boolean to decide wheather to stub or not. It should fit any advanced cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants