일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 머신러닝기초
- erc4337
- vue기초
- Vue
- ethers type
- git rebase
- SBT표준
- 컨트렉트 동일한 함수이름 호출
- rust 기초
- 스마트컨트렉트 예약어 함수이름 중복
- 오블완
- ethers websocket
- 컨트렉트 배포 자동화
- 러스트 기초
- ethers typescript
- erc4337 contract
- 러스트 기초 학습
- 스마트컨트렉트 함수이름 중복 호출
- chainlink 설명
- 스마트 컨트렉트 함수이름 중복
- 스마트컨트렉트테스트
- multicall
- 체인의정석
- ethers
- ethers v6
- ambiguous function description
- 티스토리챌린지
- 러스트기초
- Vue.js
- 계정추상화
Archives
- Today
- Total
체인의정석
Jest 에러 상황 테스트 하는 법 본문
728x90
https://jestjs.io/docs/using-matchers
Using Matchers · Jest
Jest uses "matchers" to let you test values in different ways. This document will introduce some commonly used matchers. For the full list, see the expect API doc.
jestjs.io
jest 에서 에러 상황을 테스트 하기 위해서는 다음과 같이 toThrow(Error)를 사용하거나 toThrow("에러메세지")를 사용하여 특정 에러값이 리턴되는지 체크하도록 할 수 있다.
function compileAndroidCode() {
throw new Error('you are using the wrong JDK');
}
test('compiling android goes as expected', () => {
expect(() => compileAndroidCode()).toThrow();
expect(() => compileAndroidCode()).toThrow(Error);
// You can also use the exact error message or a regexp
expect(() => compileAndroidCode()).toThrow('you are using the wrong JDK');
expect(() => compileAndroidCode()).toThrow(/JDK/);
});
이를 이용하여 오류가 나야하는 상황에서 오류가 나는지도 체크를 해주는 것이 좋다.
나는 json에서 바로 받아와서 클래스를 생성해줄 때 잘못된 형식이면 에러가 나야하므로 아래와 같이 테스트를 추가하였다.
toJSONobject에는 잘못된 값을 추가한 상태이다.
let toJSONObject = JSON.parse(JSON.stringify(ivms101Example));
console.log(toJSONObject)
expect(() => Ivms101.fromJson(toJSONObject)).toThrow(Error);
728x90
반응형
'개발' 카테고리의 다른 글
typescript 커스텀 모듈 만들어서 사용하기 (0) | 2021.07.21 |
---|---|
typescript undefined 조건문 검사 spread syntax 와 &&를 사용하여 코드 단축하기 (0) | 2021.07.19 |
Destructuring 구조분해 할당 (0) | 2021.07.16 |
객체지향 프로그래밍 하기2 (0) | 2021.07.16 |
자바스크립트 객체에서 key값과 value 값이 같은 경우 (0) | 2021.07.15 |
Comments