React

[Jest] React -Jest Qeury getBy,queryBy,findBy Example

차노도리 2023. 5. 29. 00:01

Jest Start 

https://puk0806.tistory.com/67

 

 

참고 : https://github.com/testing-library/jest-dom

 

GitHub - testing-library/jest-dom: Custom jest matchers to test the state of the DOM

:owl: Custom jest matchers to test the state of the DOM - GitHub - testing-library/jest-dom: Custom jest matchers to test the state of the DOM

github.com

 

  • getBy...
    • 쿼리에 대한 일치하는 노드르 반환하고 일치하는 요소가 없거나 둘 이상의 일치가 발견되면 오류를 발생시킨다.
    • 둘 이상의 요소가 예상되는 경우 getAllBy를 사용한다.
  • qeuryBy...
    • 쿼리에 대한 일치하는 노드르 반환하고 일치하는 요소가 없으면 null을 반환한다.
  • findBy...
    • 쿼리에 대한 일치하는 노드르 반환하고 일치하는 요소가 없거나 둘 이상의 일치가 발견되면 오류를 발생시킨다.
    • 쿼리에 대한 일치하는 요소가 발견되면 Promise를 반환한다.
    • getBy + waitFor 
    • 둘 이상의 요소를 찾아야하는 경우 findAllBy를 사용한다.

 

ex) getByText

 

ex) queryByText

 

ex) findByText