mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
refactor: make mocked log object mutable
This commit is contained in:
parent
20010a6f47
commit
9ddd56c97f
@ -1,22 +1,22 @@
|
||||
/* eslint-disable no-console */
|
||||
export default function mockConsole(levels = 'all') {
|
||||
export default function mockLog(levels = 'all', logger = console) {
|
||||
if (levels === 'all') {
|
||||
levels = ['trace', 'debug', 'log', 'info', 'warn', 'error']
|
||||
}
|
||||
beforeAll(() => {
|
||||
for (let level of levels) {
|
||||
console[level] = jest.fn()
|
||||
logger[level] = jest.fn()
|
||||
}
|
||||
})
|
||||
beforeEach(() => {
|
||||
for (let level of levels) {
|
||||
console[level].mockClear()
|
||||
logger[level].mockClear()
|
||||
}
|
||||
})
|
||||
afterAll(() => {
|
||||
for (let level of levels) {
|
||||
console[level].mockRestore()
|
||||
logger[level].mockRestore()
|
||||
}
|
||||
})
|
||||
return console
|
||||
return logger
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user