Using jest toThrow with async / await
Instead of
it("doesn't work", async () => {
const fn = async () => {
throw new Error();
};
expect(await fn()).toThrow();
});
Use
it("does work", async () => {
const fn = async () => {
throw new Error();
};
await expect(fn()).rejects.toThrow();
});
See also github.com/facebook/jest/issues/1700.