ByDisplayValue
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
一致する表示値を持つinput、textarea、またはselect要素を返します。
inputタグ
<input type="text" id="lastName" />
document.getElementById('lastName').value = 'Norris'
- ネイティブ
- React
- Angular
- Cypress
import {screen} from '@testing-library/dom'
const lastNameInput = screen.getByDisplayValue('Norris')
import {render, screen} from '@testing-library/react'
render(<MyComponent />)
const lastNameInput = screen.getByDisplayValue('Norris')
import {render, screen} from '@testing-library/angular'
await render(MyComponent)
const lastNameInput = screen.getByDisplayValue('Norris')
cy.findByDisplayValue('Norris').should('exist')
textareaタグ
<textarea id="messageTextArea" />
document.getElementById('messageTextArea').value = 'Hello World'
- ネイティブ
- React
- Angular
- Cypress
import {screen} from '@testing-library/dom'
const messageTextArea = screen.getByDisplayValue('Hello World')
import {render, screen} from '@testing-library/react'
render(<MyComponent />)
const messageTextArea = screen.getByDisplayValue('Hello World')
import {render, screen} from '@testing-library/angular'
await render(MyComponent)
const messageTextArea = screen.getByDisplayValue('Hello World')
cy.findByDisplayValue('Hello World').should('exist')
selectタグ
selectの場合、指定されたTextMatchと一致する選択された<option>を持つ<select>が検索されます。
<select>
  <option value="">State</option>
  <option value="AL">Alabama</option>
  <option selected value="AK">Alaska</option>
  <option value="AZ">Arizona</option>
</select>
- ネイティブ
- React
- Angular
- Cypress
import {screen} from '@testing-library/dom'
const selectElement = screen.getByDisplayValue('Alaska')
import {render, screen} from '@testing-library/react'
render(<MyComponent />)
const selectElement = screen.getByDisplayValue('Alaska')
import {render, screen} from '@testing-library/angular'
await render(MyComponent)
const selectElement = screen.getByDisplayValue('Alaska')
cy.findByDisplayValue('Alaska').should('exist')
オプション
TextMatchオプション