Jest Matcher
avatar
FrugalBoy
2025.01.24조회수 3회


Jest는 다른 방법으로 값을 테스트 하도록 matcher 라는 것을 사용한다. 

matcher란 '이거 맞아?' 라고 물어보는 메서드리고 보면 된다. 기대한 값이 실제 반환된 값과 일치하는 지를 확인하는 작업을 일컫는다.


아래는 matcher 예시들

toBe

expect(1 + 4).toBe(5);

toEqaul

const { getUser } = require('user'); // 테스트할 함수를 가져온다. 

test("return a user object", () => {
  // getUser(1)의 리턴 결과값이 { 객체 } 값이 같은 경우 true
  expect(getUser(1)).toEqual({
    id: 1,
    email: `user1@test.com`,
  });
});



출처: https://inpa.tistory.com/entry/JEST-📚-jest-기본-문법-정리 [Inpa Dev 👨‍💻:티스토리]

회원가입만 해도
이 글을 무료로 읽을 수 있어요.

이미 계정이 있으신가요?로그인하기
댓글 1
avatar
FrugalBoy
구독자 5명구독중 11명
Wanna live like a frugal boy For the genetically superior, success is easier to attain. But it is by no means guaranteed. After all, there is no gene for fate -Gattaca-