-
Notifications
You must be signed in to change notification settings - Fork 81
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 throw
in component causes unit test to timeout
#875
Comments
@palmer-rm Hello there! I'm a bot here to help you with bugs, questions, and becoming a contributor. Let's squash those bugs together! To resolve the issue where using the <template>
<div>
This should not display.
</div>
</template>
<script lang="ts">
export default defineComponent({
data () {
try {
throw new Error('💀')
} catch (error) {
console.error(error)
// Handle the error appropriately, e.g., set an error state
}
},
})
</script> By catching the error within the Additionally, ensure you have set up your testing environment correctly using import { defineVitestConfig } from '@nuxt/test-utils/config'
export default defineVitestConfig({
test: {
environment: 'nuxt',
// you can optionally set Nuxt-specific environment options
// environmentOptions: {
// nuxt: {
// rootDir: fileURLToPath(new URL('./playground', import.meta.url)),
// domEnvironment: 'happy-dom', // 'happy-dom' (default) or 'jsdom'
// overrides: {
// // other Nuxt config you want to pass
// }
// }
// }
}
}) This setup ensures that your tests run in a proper Nuxt environment, which can help prevent issues like timeouts due to unhandled errors [1][2][3]. |
Environment
Darwin
v20.12.2
3.12.2
3.12.0
2.9.6
[email protected]
-
devtools
,srcDir
,runtimeConfig
,modules
,typescript
,vite
@pinia/[email protected]
,@nuxt/test-utils/[email protected]
,@nuxt/[email protected]
-
Reproduction
https://stackblitz.com/edit/github-jk1bg9?file=package.json,app.nuxt.test.ts
Command:
npm run test
Describe the bug
I am using Nuxt's createError to handle errors from within Vue components.
When using the
throw
keyword inside a component, a unit test that mounts that component fails due to a timeout.This happens regardless of whether the component throws Nuxt's
createError
,newError
, or anything else, e.g:Results in:
When mounting the component using
mount
in@vue/test-utils
(whichmountSuspended
wraps IIRC), usingthrow
in a component does not result in a failed test due to timeout.Using a
try catch
in the component still causes the test to timeout, i.e:The text was updated successfully, but these errors were encountered: