Saltar al contenido principal

ByAltText

[Traducción Beta No Oficial]

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" />
import {screen} from '@testing-library/dom'

const incrediblesPosterImg = screen.getByAltText(/incredibles.*? poster/i)

Opciones

Opciones de TextMatch