-
Notifications
You must be signed in to change notification settings - Fork 83
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
Using mountSuspended()
with a component using <script setup>
and #import
makes an error
#871
Comments
FYI @danielroe |
To resolve the issue with
Here is an example of how you can achieve this: import { mountSuspended } from '@nuxt/test-utils'
import { defineNuxtComponent, tryUseNuxtApp } from '#app'
import { h } from 'vue'
const wrappedSetup = async (props, setupContext) => {
let setupState = {}
if (setup) {
const result = await setup(props, setupContext)
setupState = result && typeof result === 'object' ? result : {}
return result
}
}
const vueApp = tryUseNuxtApp()?.vueApp || globalThis.__unctx__.get('nuxt-app').tryUse().vueApp
const wrapper = await mountSuspended(defineNuxtComponent({
setup: wrappedSetup,
render: () => h('div', 'hi there'),
}))
expect(wrapper.html()).toMatchInlineSnapshot('"<div>hi there</div>"') This code ensures that the If you are still encountering issues, ensure that your component and its dependencies are correctly set up and that the Nuxt environment is properly initialized before running your tests. @danielroe, this one's a bit out of my wheelhouse, could you step in and provide your guidance? |
Is there any update on this? I'm getting a very similar error in my tests, and the workaround above does not seem feasible to be included in a simple test. |
I am running into the same issue. It's the only component/test running into this, despite all of them using <script lang="ts" setup>
const {
label,
error,
helpText,
id = 'input',
} = defineProps<{
label?: string;
error?: string;
helpText?: string;
id?: string;
}>();
const modelValue = defineModel<string | number>();
const attrs = useAttrs();
</script>
|
Possibly the same issue as #744? Any updates for this or that? |
Environment
Working directory: /home/projects/jvmibwmjx.github
Nuxt project info:
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
'smountSuspended()
API. If this component<script setup>
#import
(i.e.useRouter
,useRoute
, ...)it makes an error below and breaks entire test.
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
The text was updated successfully, but these errors were encountered: