createTestingPinia doesn't mock actions using vitest vi.fn #1250
-
ReproductionNote: the code in the branch is working with a workaround, to reproduce this issue you need to comment two lines specified at step Steps to reproduce the bug
Expected behaviorPinia actions should already be mocked with the Actual behaviorTests are breaking with
even if in the docs they say that they should be automatically stubbed with the Additional informationUsing the same code with Vue 2, Pinia and Jest is working fine. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 7 replies
-
It works on my end: Moving to a discussion until this can be reproduced |
Beta Was this translation helpful? Give feedback.
-
Note: the code in the branch is working with a workaround, to reproduce this issue you need to comment two lines specified at step |
Beta Was this translation helpful? Give feedback.
-
Ah found the culprit: it's because I'm working on a fix so this workaround isn't needed |
Beta Was this translation helpful? Give feedback.
-
Not sure if it's related, but without specifying |
Beta Was this translation helpful? Give feedback.
-
I just had a problem with an action that was called on the This is the code: onMounted(() => {
authStore.refresh().catch(() => {
/* We do nothing if we can't automatically refresh on load */
})
}) The store action This was my test code: test('mount component', () => {
expect(App).toBeTruthy()
const pinia = createTestingPinia()
const wrapper = mount(App, {
global: {
plugins: [router, pinia],
},
})
expect(wrapper.html()).toBeTruthy()
}) When running the tests it was failing with some errors that I was not able to interpret properly. const pinia = createTestingPinia({
createSpy() {
return () => {
return Promise.resolve()
}
},
}) But left me wondering what's gonna happen if I use a couple of stores (or more) on the |
Beta Was this translation helpful? Give feedback.
-
I'm getting this error but only when I run Coverage, anyone know why? |
Beta Was this translation helpful? Give feedback.
Ah found the culprit: it's because
useStore()
is called outside of mounting a component context and plugins are not added in the correct order and the devtools plugin (which should not be included in test env) override actions. You can addfakeApp: true
for the moment.I'm working on a fix so this workaround isn't needed