メインコンテンツにスキップ

ByPlaceholderText

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

これはplaceholder属性を持つすべての要素を検索し、指定されたTextMatchに一致する要素を見つけます。

<input placeholder="Username" />
import {screen} from '@testing-library/dom'

const inputNode = screen.getByPlaceholderText('Username')

注意

プレースホルダーはラベルの代替として適していないので、通常は代わりにgetByLabelTextを使用してください。

オプション

TextMatchオプション