Got the following failing test case and i'm not sure why:
foo.js
async function throws() {
throw 'error';
}
async function foo() {
try {
await throws();
} catch(e) {
console.error(e);
throw e;
}
}
test.js
const foo = require('./foo');
describe('foo', () => {
it('should log and rethrow', async () => {
await expect(foo()).rejects.toThrow();
});
});
I expect foo to throw but for some reason it just resolves and the test fails:
FAILED foo › should log and rethrow - Received function did not throw
Probably missing some basic detail of async await throw behavior.