2018-03-30 08:27:18 +00:00
|
|
|
/* eslint-disable no-console */
|
2018-04-13 06:59:22 +00:00
|
|
|
export default function mockLog(levels = 'all', logger = console) {
|
2018-03-30 08:27:18 +00:00
|
|
|
if (levels === 'all') {
|
|
|
|
levels = ['trace', 'debug', 'log', 'info', 'warn', 'error']
|
|
|
|
}
|
|
|
|
beforeAll(() => {
|
|
|
|
for (let level of levels) {
|
2018-04-13 07:25:34 +00:00
|
|
|
jest.spyOn(logger, level).mockImplementation(() => {})
|
2018-03-30 08:27:18 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
beforeEach(() => {
|
|
|
|
for (let level of levels) {
|
2018-04-13 06:59:22 +00:00
|
|
|
logger[level].mockClear()
|
2018-03-30 08:27:18 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
afterAll(() => {
|
|
|
|
for (let level of levels) {
|
2018-04-13 06:59:22 +00:00
|
|
|
logger[level].mockRestore()
|
2018-03-30 08:27:18 +00:00
|
|
|
}
|
|
|
|
})
|
2018-04-13 06:59:22 +00:00
|
|
|
return logger
|
2018-03-30 08:27:18 +00:00
|
|
|
}
|