-
-
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
fix: @pinia/nuxt breaks createTestingPinia #2578
Conversation
✅ Deploy Preview for pinia-playground canceled.
|
✅ Deploy Preview for pinia-official canceled.
|
The reason is that there is a conflict between the pinia instance created by @pinia/nuxt and createTestingPinia. Ultimately, the pinia instance created by @pinia/nuxt takes precedence, causing the tests to fail. |
packages/testing/src/testing.ts
Outdated
const app: App = (globalThis as any).__unctx__.get('nuxt-app').tryUse().vueApp | ||
const symbols = Object.getOwnPropertySymbols(app._context.provides) | ||
const nuxtPinia: Pinia = app._context.provides[symbols[0]] | ||
const pinia = nuxtPinia ?? createPinia() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks but not only we always want to create a new pinia instance here, this code is relying on internals and globals that are specific to nuxt. This will break in any other scenario
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is temporary fix code. You are right, this code lacks flexibility. However, there is another issue where addPlugin
from @pinia/nuxt
creates a new pinia instance, which conflicts with the creation of createTestingPinia
. But the logic of @nuxt/pinia
is reasonable, and I believe it should not be modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's okay to adapt @nuxt/pinia
to work with the test environment. It's really crucial to always create a new pinia instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it.
d88b1e8
to
5ec01cf
Compare
Sad :-(. It's diffcult to me. I gave up. I have subscribed to this issue, so please go ahead and fix it. I would like to learn how it is fixed. |
No worries, thanks for the try! |
fix #2555