test-utils
test-utils copied to clipboard
Fail to mock a Nested Component with mockComponent
Environment
- Operating System: Linux
- Node Version: v18.18.0
- Nuxt Version: 3.9.1
- CLI Version: 3.10.0
- Nitro Version: 2.8.1
- Package Manager: [email protected]
- Builder: -
- User Config: devtools
- Runtime Modules: -
- Build Modules: -
Reproduction
https://stackblitz.com/edit/nuxt-starter-ashrbf?file=test%2Fmock.test.ts
Describe the bug
When I try to use the mockComponent helper in a new nuxt project, the test can't mock a nested component properly.
I tried the method to mock another similar components, but in this case doesn't work.
Additional context
It seams to be related if the components are in a subfolder inside the components folder. If the components are in the component folder, it works.
It will be great to have an example with several test inside the same test suite, to explain how to manage unstubbing between tests.
Logs
No response
Using the vue test utils' stubs attribute to stub a nested component seems to be working:
await renderSuspended(MyComponent, {
global : {
stubs : {
DeeplyNestedComponent : {
template : 'Stubbed'
},
}
},
});
This will work fine for now, however I feel like this is something which the mockComponent function should be able to do.