getByPlaceholderText, queryByPlaceholderText, getAllByPlaceholderText, queryAllByPlaceholderText, findByPlaceholderText, findAllByPlaceholderText
API
getByPlaceholderText(
// If you're using `screen`, then skip the container argument:
container: HTMLElement,
text: TextMatch,
options?: {
exact?: boolean = true,
normalizer?: NormalizerFn,
}): HTMLElement
这将搜索所有带有占位符属性的元素,并找到与给定的 TextMatch 匹配的元素。
<input placeholder="Username" />
import {screen} from '@testing-library/dom'
const inputNode = screen.getByPlaceholderText('Username')
注意:占位符不能代替标签,因此你通常应该使用 getByLabelText 代替。