You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
assert() just throws exception and DOESN'T reject Promise that we expect in out test.
In this case sometimes we see UnhandledPromiseRejectionWarning.
Case 1
const eventEmitter = new EventEmitter();
const onEventA = expect(eventEmitter).to.not.emit('eventA');
eventEmitter.emit('eventA'); // <--- HERE we get exception from on() handler
await onEventA; // NOT HERE !
});
Case 2
const eventEmitter = new EventEmitter();
const onEventA = expect(eventEmitter).to.emit('eventA');
await onEventA; // Promise will be NEVER resolved
// Test fails only because setTimeout throws an error and mocha handles it
});
Wrong Promise rejection implementation:
assert()
just throws exception and DOESN'T reject Promise that we expect in out test.In this case sometimes we see
UnhandledPromiseRejectionWarning
.Case 1
Case 2
Tech details
process.on('uncaughtException', uncaught)
:https://github.com/mochajs/mocha/blob/master/lib/runner.js#L871
Possible solution
Use
try-catch
forsetTimeout()
andon()
handlers:The text was updated successfully, but these errors were encountered: