有什么方法可以监视 bunyan 日志以确保打印出我期望的内容?
我的文件.js
const bunyan = require('bunyan');
const log = bunyan.createLogger({name: 'FailureAuditService'});
class someClass {
someFunct() {
if(x) {
log.warn('something happened');
}
}
}
测试
const service = require(../MyFile);
describe('test something', () => {
it('Will test the bunyan log', res => {
let consoleLog = sinon.spy(log, 'createLogger');
let x = true;
service.someClass(x).then(res => {
let expected = 'something happened';
consoleLog.should.equal(expected);
});
});
})