Skip to content

Commit 19922d9

Browse files
docs: add onConsoleLog (#4115)
1 parent 3c30585 commit 19922d9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

docs/config/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,3 +1619,26 @@ By default Vitest will run all of your test cases even if some of them fail. Thi
16191619
- **Version:** Since Vitest 0.32.3
16201620

16211621
Retry the test specific number of times if it fails.
1622+
1623+
### onConsoleLog
1624+
1625+
- **Type**: `(log: string, type: 'stdout' | 'stderr') => false | void`
1626+
1627+
Custom handler for `console.log` in tests. If you return `false`, Vitest will not print the log to the console.
1628+
1629+
Can be useful for filtering out logs from third-party libraries.
1630+
1631+
```ts
1632+
import { defineConfig } from 'vitest/config'
1633+
1634+
export default defineConfig({
1635+
test: {
1636+
onConsoleLog(log: string, type: 'stdout' | 'stderr'): boolean | void {
1637+
if (log === 'message from third party library' && type === 'stdout') {
1638+
return false;
1639+
}
1640+
},
1641+
},
1642+
})
1643+
```
1644+

0 commit comments

Comments
 (0)