mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-05 21:53:56 +00:00
25 lines
599 B
JavaScript
25 lines
599 B
JavaScript
/* eslint-disable no-console */
|
|
export default function mockLog(levels = 'all', logger = console) {
|
|
if (levels === 'all') {
|
|
levels = ['trace', 'debug', 'log', 'info', 'warn', 'error']
|
|
} else if (typeof levels === 'string') {
|
|
levels = [levels]
|
|
}
|
|
beforeAll(() => {
|
|
for (const level of levels) {
|
|
jest.spyOn(logger, level).mockImplementation(() => {})
|
|
}
|
|
})
|
|
beforeEach(() => {
|
|
for (const level of levels) {
|
|
logger[level].mockClear()
|
|
}
|
|
})
|
|
afterAll(() => {
|
|
for (const level of levels) {
|
|
logger[level].mockRestore()
|
|
}
|
|
})
|
|
return logger
|
|
}
|