PorTextoPlaceholder
Esta página fue traducida por PageTurner AI (beta). No está respaldada oficialmente por el proyecto. ¿Encontraste un error? 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
Esto buscará todos los elementos con un atributo placeholder y encontrará uno que coincida con el TextMatch proporcionado.
<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
Un placeholder no es un buen sustituto para una etiqueta, por lo que generalmente deberías usar
getByLabelTexten su lugar.
Opciones
Opciones de TextMatch