Question: How to test what kind of error an async function throws and how to apply matchers to the rejected value?
Answer: You need to await
the expect
call and then inspect the rejects
property of the returned Jest object.
async function doSomethingAsync(value?: string) {
if (!value) throw new MyFancyError('Some error text');
return value;