ByAltText[Testing Library]

SnowCat·2023년 3월 6일
0

Testing Library

목록 보기
6/11
post-thumbnail
getByAltText(
  container?: HTMLElement,
  text: TextMatch,
  options?: {
    exact?: boolean = true,
    normalizer?: NormalizerFn,
  }): HTMLElement

//component
<img alt="Incredibles 2 Poster" src="/incredibles-2.png" />

//test
import {screen} from '@testing-library/dom'

const incrediblesPosterImg = screen.getByAltText(/incredibles.*? poster/i)
  • alt 속성이 있는 개체의 alt text가 일치하는지 확인하는 메서드
profile
냐아아아아아아아아앙

0개의 댓글