ByAltText
Esta página fue traducida por PageTurner AI (beta). No está respaldada oficialmente por el proyecto. ¿Encontraste un error? Reportar problema →
getByAltText, queryByAltText, getAllByAltText, queryAllByAltText, findByAltText, findAllByAltText
API
getByAltText(
// If you're using `screen`, then skip the container argument:
container: HTMLElement,
text: TextMatch,
options?: {
exact?: boolean = true,
normalizer?: NormalizerFn,
}): HTMLElement
Esto devolverá el elemento (normalmente un <img>) que contenga el texto alt
especificado. Ten en cuenta que solo admite elementos que acepten un atributo alt o
elementos personalizados
(ya que no sabemos si un elemento personalizado implementa alt o no):
<img>,
<input>,
y <area>
(excluyendo intencionalmente
<applet>
por estar obsoleto).
<img alt="Incredibles 2 Poster" src="/incredibles-2.png" />
- Native
- React
- Angular
- Cypress
import {screen} from '@testing-library/dom'
const incrediblesPosterImg = screen.getByAltText(/incredibles.*? poster/i)
import {render, screen} from '@testing-library/react'
render(<MyComponent />)
const incrediblesPosterImg = screen.getByAltText(/incredibles.*? poster/i)
import {render, screen} from '@testing-library/angular'
await render(MyComponent)
const incrediblesPosterImg = screen.getByAltText(/incredibles.*? poster/i)
cy.findByAltText(/incredibles.*? poster/i).should('exist')
Opciones
Opciones de TextMatch