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" />
- ネイティブ
- React
- Angular
- Cypress
import {screen} from '@testing-library/dom'
const inputNode = screen.getByPlaceholderText('Username')
import {render, screen} from '@testing-library/react'
render(<MyComponent />)
const inputNode = screen.getByPlaceholderText('Username')
import {render, screen} from '@testing-library/angular'
await render(MyComponent)
const inputNode = screen.getByPlaceholderText('Username')
cy.findByPlaceholderText('Username').should('exist')
注意
プレースホルダーはラベルの代替として適していないので、通常は代わりに
getByLabelText
を使用してください。
オプション
TextMatchオプション