• 카테고리

    질문 & 답변
  • 세부 분야

    프론트엔드

  • 해결 여부

    미해결

jest와 @testing-library/jest-dom

21.12.24 23:33 작성 조회수 820

1

너무 기초적인 질문인 것 같아 걱정이지만 질문드립니다~!

1. jest와 @testing-library/jest-dom는 어떤 차이가 있고 각각의 역할이 궁금합니다.

2. @testing-library와 함께 사용하는 이유와 jest만 따로 사용하지는 않는 이유가 궁금합니다.

 

 

답변 1

답변을 작성해보세요.

6

안녕하세요 ! 

좋은 질문 감사합니다! 
React Testing Library는 요소를 렌더링 하는 부분을 다루고, Jest는  Dom의 노드들을 테스트합니다.

1. jest와 @testing-library/jest-dom는 어떤 차이가 있고 각각의 역할이 궁금합니다.

이 질문의 답변은 

The problem

You want to use jest to write tests that assert various things about the state of a DOM. As part of that goal, you want to avoid all the repetitive patterns that arise in doing so. Checking for an element's attributes, its text content, its css classes, you name it.

This solution

The @testing-library/jest-dom library provides a set of custom jest matchers that you can use to extend jest. These will make your tests more declarative, clear to read and to maintain.

 

이렇게 봐주시면 되는데 testing-library와 함께 쓰는데 훨씬 효율적으로 사용할 수 있게 해줍니다.

 

2. @testing-library와 함께 사용하는 이유와 jest만 따로 사용하지는 않는 이유가 궁금합니다.

이 부분은 
React Testing Library는 요소를 렌더링 하는 부분을 다루고, Jest는  Dom의 노드들을 테스트합니다.

이렇게 얘기하신 것 처럼 두개가 다른 역할을 하기 때문입니다.  
감사합니다 !