테스트/단위 테스트 (Vue)

단위 테스트 - Jest Matchers

IT Blue 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)
})

 

결과

 


 

참고

https://jestjs.io/docs/expect

 

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