onConsoleLog
ts
function onConsoleLog(
log: string,
type: 'stdout' | 'stderr',
entity: TestModule | TestSuite | TestCase | undefined,
): boolean | voidCustom handler for console methods in tests. If you return false, Vitest will not print the log to the console. Note that Vitest ignores all other falsy values.
Can be useful for filtering out logs from third-party libraries.
ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
onConsoleLog(log: string, type: 'stdout' | 'stderr'): boolean | void {
return !(log === 'message from third party library' && type === 'stdout')
},
},
})