Aller au contenu principal

ParTexteAlternatif

[Traduction Bêta Non Officielle]

Cette page a été traduite par PageTurner AI (bêta). Non approuvée officiellement par le projet. Vous avez trouvé une erreur ? Signaler un problème →

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

Cette méthode renvoie l'élément (généralement une balise <img>) possédant le texte alternatif (alt) spécifié. Notez qu'elle ne prend en charge que les éléments acceptant un attribut alt ou les éléments personnalisés (puisque nous ne pouvons pas savoir si un élément personnalisé implémente alt ou non) : <img>, <input>, et <area> (en excluant volontairement <applet> car cette balise est dépréciée).

<img alt="Incredibles 2 Poster" src="/incredibles-2.png" />
import {screen} from '@testing-library/dom'

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

Options

options TextMatch