Skip to content

Commit 0652c1f

Browse files
committed
docs: document onUnhandledError
1 parent 6d9001f commit 0652c1f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/config/index.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,30 @@ export default defineConfig({
21912191
})
21922192
```
21932193

2194+
### onUnhandledError<NonProjectOption /> {#onunhandlederror}
2195+
2196+
- **Type:** `(error: (TestError | Error) & { type: string }) => boolean | void`
2197+
2198+
A custom handler to filter out unhandled errors that should not be reported. If an error is filtered out, it will no longer affect the test results.
2199+
2200+
If you want unhandled errors to be reported without impacting the test outcome, consider using the [`dangerouslyIgnoreUnhandledErrors`](#dangerouslyIgnoreUnhandledErrors) option
2201+
2202+
```ts
2203+
import type { ParsedStack } from 'vitest'
2204+
import { defineConfig } from 'vitest/config'
2205+
2206+
export default defineConfig({
2207+
test: {
2208+
onUnhandledError(error): boolean | void {
2209+
// Ignore all errors with the name "MySpecialError".
2210+
if (error.name === 'MySpecialError') {
2211+
return false
2212+
}
2213+
},
2214+
},
2215+
})
2216+
```
2217+
21942218
### diff
21952219

21962220
- **Type:** `string`

0 commit comments

Comments
 (0)