Jest で async 関数のエラーを検証する


環境

  • Jest: 26.1.0
  • Typescript: 3.9.7

検証したい関数

const fail = async () => {
  throw new Error();
}

テスト

await expect(fail).rejects.toThrowError(Error);

参考