I want to check if an async function throws using assert.throws from the native assert
module.
I tried with
const test = async () => await aPromi
Since the question is still getting attention, I'd like to sum up the two best solutions, especially to highlight the new standard method.
There's a dedicated method in the assert library, assert.rejects.
A fill from vitalets answer:
import assert from 'assert';
async function assertThrowsAsync(fn, regExp) {
let f = () => {};
try {
await fn();
} catch(e) {
f = () => {throw e};
} finally {
assert.throws(f, regExp);
}
}