test-utils
test-utils copied to clipboard
Using `mountSuspended()` with a component using `<script setup>` and `#import` makes an error
Environment
Working directory: /home/projects/jvmibwmjx.github Nuxt project info:
- Operating System: Linux
- Node Version: v18.20.3
- Nuxt Version: 3.12.2
- CLI Version: 3.12.0
- Nitro Version: 2.9.6
- Package Manager: [email protected]
- Builder: -
- User Config: devtools
- Runtime Modules: -
- Build Modules: -
Reproduction
https://stackblitz.com/edit/github-mmtufx?file=app.vue
Describe the bug
Let's say there is a root component which I want to mount using @nuxt/test-utils
's mountSuspended()
API. If this component
- uses
<script setup>
- imports composable API from Nuxt
#import
(i.e.useRouter
,useRoute
, ...)
it makes an error below and breaks entire test.
stdout | createSuspenseBoundary (/home/projects/jvmibwmjx.github/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:1451:43)
<Suspense> is an experimental feature and its API will likely change.
stderr | warn$1 (/home/projects/jvmibwmjx.github/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:50:13)
[Vue warn]: Cannot mutate <script setup> binding "useRouter" from Options API.
at <MountSuspendedComponent >
at <MountSuspendedHelper>
at <Anonymous ref="VTU_COMPONENT" >
at <VTUROOT>
[Vue warn]: Unhandled error during execution of render function
at <MountSuspendedComponent >
at <MountSuspendedHelper>
at <Anonymous ref="VTU_COMPONENT" >
at <VTUROOT>
Only if the root component meets the condition above, the issue occurs. As you see in the reproduction, if you use #imports
and <script setup>
in child elements it work fine.
The app itself is built and works fine if I run it.
You can reproduce the issue with the repository link above.
Additional context
No response
Logs
No response