【发布时间】:2017-10-23 22:14:45
【问题描述】:
我想测试一下,如果在fs.writeFile 期间发生错误,则会向控制台日志输出一条消息。下面的测试确实通过了,但它会将错误的堆栈跟踪输出到测试控制台,这是不需要的。如何避免?
describe('with fs error', () => {
it('should output errors to console', () => {
sandbox.stub(fs, 'writeFile').yields(new Error('write error'));
const consoleSpy = sandbox.spy(console, 'log');
history.save();
expect(consoleSpy).to.have.been.calledOnce;
});
});
【问题讨论】:
-
我想我也想测试一下确切的错误信息。
标签: node.js mocha.js sinon chai