我正在围绕pinojs中的 javascript 库构建一个包装器。我想知道如何编写单元测试来验证其中的info函数是否pino被实际调用。
这是一个代码片段
const { logger } = require(`../../../lib/index`);
describe(`when logger is configured with pino-pretty`, () => {
beforeEach(() => {
myAppLogger = logger({
prettyPrint: true
});
});
it(`then pino info method is called on pino instance`, () => {
const pinoSpy = sinon.spy(pino, 'info');
myAppLogger.info('info message');
expect(pinoSpy).to.have.been.called;
expect(pinoSpy).to.not.throw();
});
});
wheremyAppLogger只是一个实例pino
pino(options, stream).child(props);