[英]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);' 或'完成(新錯誤(“應該從未達到過”));' 有沒有辦法說
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.