JestでPromiseを返す関数の中で例外を送出するゲースを確認するテストを書いた際に以下のエラーがでて、テストが失敗しました。
Received function did not throw 271 | expect(async () => { 272 | await service.authenticate2fa(-1, "0123456", res); > 273 | }).toThrowError(NotFoundException);テストは以下のように書いていました。
expect(async () => { await service.authenticate2fa(-1, "0123456", res); }).toThrowError(NotFoundException);所望の動作をするテストの書き方は以下のとおりでした。
expect(async () => {
await service.authenticate2fa(-1, "0123456", res);
}).rejects.toThrowError(NotFoundException);
マニュアルの該当箇所はAn Async Example · Jestです。