ParTexteAlternatif
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" />
- 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')
Options
options TextMatch