-
단위 테스트 - Jest Matchers테스트/단위 테스트 (Vue) 2021. 9. 4. 02:52
단위 테스트 - Jest Matchers (일치 도구)
/* example.test.js */ const userA = { name: 'ITBlue', age: 35 } const userB = { name: 'ITRed', age: 25 } // expect(데이터) // toBe(비교할 기대값 작성 - 원시 데이터) // toEqual(비교할 기대값 작성 - 참조형 데이터) test('데이터 일치', () => { expect(userA.age).toBe(35) expect(userA).toEqual({ name: 'ITBlue', age: 35 }) }) // not - 거짓을 참으로, 참을 거짓으로 test('데이터 불일치', () => { expect(userB.name).not.toBe('ITDark') expect(userB).not.toEqual(userA) })
결과
참고
Expect · Jest
When you're writing tests, you often need to check that values meet certain conditions. expect gives you access to a number of "matchers" that let you validate different things.
jestjs.io
'테스트 > 단위 테스트 (Vue)' 카테고리의 다른 글
단위 테스트 - VTU 테스트 및 API (0) 2021.09.07 단위 테스트 - 모의(Mock) 함수 (0) 2021.09.05 단위 테스트 - 비동기 테스트 (0) 2021.09.04 단위 테스트 - Jest Globals (0) 2021.09.03 단위 테스트 - 테스트 환경 구성 (0) 2021.09.01