Aller au contenu principal

ByPlaceholderText

[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 →

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

Cette méthode recherche tous les éléments ayant un attribut placeholder et en trouve un qui correspond au TextMatch donné.

<input placeholder="Username" />
import {screen} from '@testing-library/dom'

const inputNode = screen.getByPlaceholderText('Username')

Note

Un placeholder n'est pas un bon substitut à un label. Vous devriez donc généralement utiliser getByLabelText à la place.

Options

options TextMatch