Testing Library의 Queries

2023. 3. 28.·🎨 프론트엔드 공부/기타

📍참고

https://testing-library.com/docs/queries/about

 

About Queries | Testing Library

Overview

testing-library.com

 

📍Queries

✅testing-library 에서 제공하는 API

- Element를 찾을 수 있게 도와주는 역할

- DOM API의 querySelector 와 비슷하다

- 예시

  // <input> 을 모두 찾을 때
  const inputs = screen.getAllByRole("textbox");
  
  // <button> 을 1개 찾을 때
  const button = screen.getByRole("button");

 

✅Query Type

 

✅Query Priority

- getByRole : aria-role 기반으로 탐색

- getByLabelText : <label> 을 기반으로 탐색 (form 에서 유용)

- getByPlaceholderText : placeholder 어트리뷰트로 탐색

 

등등..

 

특히, getByRole Query를 이해하려면, ARIA Role을 짚고 넘어가야 한다

 

📍ARIA Role

ARIA Role 은 스크린 리더를 위해 HTML Element의 목적을 명시한다

- role은 명시적으로 부여될 수도 있고 (role 어트리뷰트)

- 자동으로 할당될 수도 있다 

 

✅참고

https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles

 

WAI-ARIA Roles - Accessibility | MDN

ARIA roles provide semantic meaning to content, allowing screen readers and other tools to present and support interaction with object in a way that is consistent with user expectations of that type of object. ARIA roles can be used to describe elements th

developer.mozilla.org

 

✅예시

heading : <h1> ~ <h6>

list : <ul>,  <li> 등

button : button

link : <a>

textbox : <input type="text">

'🎨 프론트엔드 공부/기타' 카테고리의 다른 글
  • npm workspace로 모노레포 구축하기
  • Matchers (Jest, RTL)
  • CRA 환경의 내장 testing 라이브러리
  • [웹 접근성] ARIA (Accessible Rich Internet Applications)
지식물원
지식물원
지식이 자라는 식물원!
  • 지식물원
    지식물원
    지식물원
  • 전체
    오늘
    어제
    • 분류 전체보기 (516)
      • 🎨 프론트엔드 공부 (253)
        • JS & TS (92)
        • HTML & CSS (22)
        • React & Next (49)
        • Vue & Nuxt (22)
        • 기타 (68)
      • 🤓 기술 학습 & 공부 기록 (116)
        • Node.js (0)
        • Python (37)
        • 백엔드 (0)
        • 딥러닝 (1)
        • 컴퓨터 일반 (72)
        • 개발 인프라 (6)
      • 👨‍💻 프로젝트 경험 (6)
        • Work (0)
        • Toy (6)
      • ⚙️ 개발 팁 & 노하우 (21)
        • 프론트엔드 (6)
        • 기타 (15)
      • ☕️ 커리어 & 인터뷰 준비 (88)
        • 코딩 테스트 (88)
      • 📰 기술 트렌드 & 생각 정리 (4)
      • 📚 기타 (25)
        • 마케팅 (15)
        • 비개발서적 (10)
  • 블로그 메뉴

    • 태그
  • 링크

  • 공지사항

    • 모바일 접속 시 코드 하이라이팅 깨질 때
  • 인기 글

  • hELLO· Designed By정상우.v4.10.3
지식물원
Testing Library의 Queries
상단으로

티스토리툴바