getByText
, queryByText
, findByText
, getAllByText
, queryAllByText
, findAllByText
getByText(
// If you're using `screen`, then skip the container argument:
container: HTMLElement,
text: TextMatch,
options?: {
selector?: string = '*',
exact?: boolean = true,
ignore?: string|boolean = 'script, style',
normalizer?: NormalizerFn,
}): HTMLElement
// example
screen.getByText('ok!');
주어진 TextMatch와 일치하는 textContent가 있는 텍스트 노드가 있는 모든 요소를 검색합니다.
단일 요소가 예상된다면 *ByText
, 복수 요소가 예상된다면 *AllByText
<a href="/about">About ℹ️</a>
Native
import {screen} from '@testing-library/dom'
const aboutAnchorNode = screen.getByText(/about/i);
React
import {screen, render} from '@testing-library/react'
render(<MyComponent/>)
const aboutAnchorNode = screen.getByText(/about/i);