繁体   English   中英

我怎么能期望摩卡测试失败?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM