我怎么能期望摩卡测试失败?
How can I expect for a failure in a Mocha test?
我正在测试一段代码,我想专门测试某个事件从未被触发。
eventBus.once("property:change", function(msg) {
expect(true).to.eq(false);
done();
});
而不是 'expect(true).to.eq(false);' 或 'done(new Error("should have never been reached"));' 有没有办法说
fail("should have never been reached"):
后者会更有表现力。有没有这样的statement/solution,没找到
我会使用间谍 - 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);
我正在测试一段代码,我想专门测试某个事件从未被触发。
eventBus.once("property:change", function(msg) {
expect(true).to.eq(false);
done();
});
而不是 'expect(true).to.eq(false);' 或 'done(new Error("should have never been reached"));' 有没有办法说
fail("should have never been reached"):
后者会更有表现力。有没有这样的statement/solution,没找到
我会使用间谍 - 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);