Aller au contenu principal

ParValeurAffichée

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

getByDisplayValue, queryByDisplayValue, getAllByDisplayValue, queryAllByDisplayValue, findByDisplayValue, findAllByDisplayValue

API

getByDisplayValue(
// If you're using `screen`, then skip the container argument:
container: HTMLElement,
value: TextMatch,
options?: {
exact?: boolean = true,
normalizer?: NormalizerFn,
}): HTMLElement

Renvoie l'élément input, textarea ou select qui possède la valeur affichée correspondante.

input tags

<input type="text" id="lastName" />
document.getElementById('lastName').value = 'Norris'
import {screen} from '@testing-library/dom'

const lastNameInput = screen.getByDisplayValue('Norris')

textarea tags

<textarea id="messageTextArea" />
document.getElementById('messageTextArea').value = 'Hello World'
import {screen} from '@testing-library/dom'

const messageTextArea = screen.getByDisplayValue('Hello World')

select tags

Dans le cas d'un select, cette fonction recherchera un <select> dont l'<option> sélectionnée correspond au TextMatch donné.

<select>
<option value="">State</option>
<option value="AL">Alabama</option>
<option selected value="AK">Alaska</option>
<option value="AZ">Arizona</option>
</select>
import {screen} from '@testing-library/dom'

const selectElement = screen.getByDisplayValue('Alaska')

Options

options TextMatch