ByPlaceholderText
Esta página foi traduzida por PageTurner AI (beta). Não é oficialmente endossada pelo projeto. Encontrou um erro? Reportar problema →
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
Esta função buscará todos os elementos com um atributo placeholder e encontrará um que corresponda ao TextMatch fornecido.
<input placeholder="Username" />
- Native
- 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')
Nota
Um placeholder não é um bom substituto para uma label, então você deve usar preferencialmente
getByLabelTextem seu lugar.
Opções
Opções de TextMatch