What you are describing is normal behavior for mocha. This code illustrates what happens if you donβt try to catch exceptions in asynchronous code (even if statement failures) and what you can do if you want to avoid the exception exception message:
var assert = require("assert"); it("fails with uncaught exception", function (done) { setTimeout(function () { assert.equal(1, 2); done(); }, 1000); }); it("fails with assertion error", function (done) { setTimeout(function () { try { assert.equal(1, 2); done(); } catch (e) { done(e); } }, 1000); });
The above code produces this output:
1) fails 2) fails 0 passing (2s) 2 failing 1) fails: Uncaught AssertionError: 1 == 2 at null._onTimeout (/tmp/t2/test.js:5:16) at Timer.listOnTimeout [as ontimeout] (timers.js:112:15) 2) fails: AssertionError: 1 == 2 at null._onTimeout (/tmp/t2/test.js:13:20) at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
Louis source share