Ir para o conteúdo principal

ByDisplayValue

[Tradução Beta Não Oficial]

Esta página foi traduzida por PageTurner AI (beta). Não é oficialmente endossada pelo projeto. Encontrou um erro? Reportar problema →

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

Retorna o elemento input, textarea ou select que possui o valor de exibição correspondente.

Elementos input

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

const lastNameInput = screen.getByDisplayValue('Norris')

Elementos textarea

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

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

Elementos select

No caso de select, isso irá procurar por um <select> cujo <option> selecionado corresponda ao TextMatch fornecido.

<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')

Opções

Opções de TextMatch