How to test the type of a thrown exception in Jest1 Jest로 Error 검증시 catch 보다는 expect Jest를 통한 테스트를 작성하다보면 Exception에 대한 검증을 작성해야할 때가 있다. 이럴때 보통 2가지 방법 중 하나를 선택한다. try ~ catch expect.rejects.toThrowError 실제 코드로는 다음과 같다. // try ~ catch it("[try/catch] 주문금액이 -이면 BadParameter Exception 을 던진다.", async () => { try { await acceptOrder({amount: -1000}); } catch (e) { expect(e).toBeInstanceOf(BadParameterException); expect(e.message).toBe('승인 요청 주문의 금액은 -가 될 수 없습니다'); } }); // expect it(.. 2022. 3. 18. 이전 1 다음