In my mocha.js test, I'm calling an async
function that throws an error, but the test doesn't fail. It passes and there is an UnhandledPromiseRejectionWarning
:
describe('async function', async function () {
it('should fail', async function () {
[1].forEach(async function () {
throw new Error("Why can't I see this error?!");
});
});
});
Note, that a simpler case works as expected:
describe('async function', async function () {
it('should fail', async function () {
throw new Error('This one fails the test');
});
});
How can I cause the test to fail due to an exception in an inner function?
(I've tried adding an unhandledRejection
handler, but the test still passes)