Can you write async tests that expect toThrow?

You can test your async function like this:

it('should test async errors', async () =>  {        
    await expect(failingAsyncTest())
    .rejects
    .toThrow('I should fail');
});

‘I should fail’ string will match any part of the error thrown.

Leave a Comment