How can I expect Mocha test to fail?
I am testing a piece of code where I want to specifically check that some event is never fired.
eventBus.once("property:change", function(msg) {
expect(true).to.eq(false);
done();
});
Instead of "expect (true) .to.eq (false)"; or "done (new error (" should never have been reached ")); is there a way to say
fail("should have never been reached"):
The latter would be much more expressive. Is there any expression / solution like this could not be found.
+3
source to share
1 answer
I would use a spy - 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);
+3
source to share