Nuxt/test/utils/mock-log.js

25 lines
593 B
JavaScript
Raw Normal View History

/* 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 (let level of levels) {
2018-04-13 07:25:34 +00:00
jest.spyOn(logger, level).mockImplementation(() => {})
}
})
beforeEach(() => {
for (let level of levels) {
logger[level].mockClear()
}
})
afterAll(() => {
for (let level of levels) {
logger[level].mockRestore()
}
})
return logger
}