javascript-我如何期望Mocha测试失败?
作者:互联网
我正在测试一段代码,在该代码中我要专门测试某个事件从未触发.
eventBus.once("property:change", function(msg) {
expect(true).to.eq(false);
done();
});
而不是’expect(true).to.eq(false);’或’done(new Error(“应该从未达到”));’有没有办法说
fail("should have never been reached"):
后者将更具表现力.是否有这样的声明/解决方案,找不到任何声明/解决方案.
解决方法:
我会使用间谍-http://sinonjs.org/
var callback = sinon.spy();
eventBus.once("property:change", callback);
// Things that could potentially but should not trigger the event
assert.equals(callback.callCount, 0);
标签:mocha,javascript 来源: https://codeday.me/bug/20191120/2041062.html