Open with-heart opened 1 month ago
Failing
throw
test: stackblitz.com/edit/vitest-dev-vitest-eujrhm?file=test/throw.test.ts
The error you threw is correctly caught because there is a try/catch handler for every test, so it's not unhandled. I don't think you can trigger a global error
event in tests because even file imports have guards, you'd need to detach the throw from the current context somehow, and the only way I know how it is by throwing an error asynchronously and not awaiting the promise, but that would be unhandledrejection
, not error
.
Describe the bug
When registering a global error listener using
addEventListener
with bothjsdom
andhappy-dom
environments, the listener is not called by an error being thrown.Dispatching an
ErrorEvent
usingdispatchEvent
does cause the listener to be called.Reproduction
Failing
throw
test: https://stackblitz.com/edit/vitest-dev-vitest-eujrhm?file=test%2Fthrow.test.tsPassing
dispatchEvent
test: https://stackblitz.com/edit/vitest-dev-vitest-eujrhm?file=test%2Fdispatch.test.tsSystem Info
Used Package Manager
yarn
Validations