-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
upstreamThe fix depends on a dependencyThe fix depends on a dependency⛰ pkg:nuxtRelated to @pinia/nuxtRelated to @pinia/nuxt✨ enhancementNew feature or requestNew feature or request🧪 pkg:testingRelated to the @pinia/testing packageRelated to the @pinia/testing package
Description
Reproduction
https://github.com/antoinezanardi/nuxt-pinia-testing
Steps to reproduce the bug
- Clone the reproduction repository.
- Run
pnpm install - Run
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 :
fetchAndSetRoles # <- This is the log from the store method, proving it's called and not correctly mocked.
stderr | tests/unit/app.nuxt.spec.ts > App Component > Store > should call method from store when mounted.
[Vue warn]: App already provides property with key "Symbol(pinia)". It will be overwritten with the new value. # <- This warning is not expected.
FAIL tests/unit/app.nuxt.spec.ts > App Component > Store > should call method from store when mounted.
TypeError: [Function] is not a spy or a call to a spy! # <- Store is not mockedAdditional 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.
// nuxt.config.ts
export default defineNuxtConfig({
modules: [
//"@pinia/nuxt", <- If you comment this line, the test passes …!
],
devtools: { enabled: true }
})rinux55, guylil, brolnickij and bborlet
Metadata
Metadata
Assignees
Labels
upstreamThe fix depends on a dependencyThe fix depends on a dependency⛰ pkg:nuxtRelated to @pinia/nuxtRelated to @pinia/nuxt✨ enhancementNew feature or requestNew feature or request🧪 pkg:testingRelated to the @pinia/testing packageRelated to the @pinia/testing package
Type
Projects
Status
💬 In discussion