-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pinia Nuxt module breaks the createTestingPinia
helper in tests
#2555
Comments
Maybe the source code is using a different version of Pinia or is not setting the |
While waiting for this bug to be fixed, here is my quick dirty fix solution : // nuxt.config.ts
const modules = [
process.env.NODE_ENV !== "test" && "@pinia/nuxt",
];
export default defineNuxtConfig({
app: { head: { link: [{ rel: "icon", type: "image/png", href: "/favicon.png" }] } },
modules,
devtools: { enabled: true },
typescript: {
strict: true,
typeCheck: true,
},
}); As you can see, I add the pinia nuxt module in my This way, you can enjoy the pinia nuxt module when running your app and disable it when you want to mock them in your unit tests. |
FYI, the |
The When checking the env, I can assure you that the |
I see, I misread that. For anybody, feel free to try to fix this and submit a PR 👍 |
I took a look, and the issue appears to be in the |
issue was fixed downstream in |
@lucasecdb i've upgraded @vue/test-utils to 2.4.6, we still cannot use
still giving an error: "[Vue warn]: App already provides property with key "Symbol(pinia)". It will be overwritten with the new value." workaround from @antoinezanardi worked, but there's cases, when you want to test an actual store instead of mocks. |
@avxkim can you create a minimal reproduction repository? I haven't had any issues since May with using testing pinia in my tests |
Do you use |
we use the way we pass testing pinia to Nuxt renderSuspended is the same as in your example: const mountComponent = async () => {
const testingPinia = createTestingPinia(/* ... */);
return await renderSuspended(Component, {
global: {
plugins: [testingPinia],
},
});
}; |
Reproduction
https://github.com/antoinezanardi/nuxt-pinia-testing
Steps to reproduce the bug
pnpm install
vitest --config vitest.unit-config.ts
Expected behavior
The test should pass as the method from store is called when the component is mounted.
Actual behavior
When using the
createTestingPinia
util method in a Nuxt project, the stores are not correctly mocked.I created a simple test which expect a method from a store to be called when the component is mounted.
However, the test fails with the following logs :
Additional information
I'm pretty sure that the nuxt module is the source of the problem.
If you comment the module in the
nuxt.config.ts
at the root of the project, the test passes.The text was updated successfully, but these errors were encountered: