ByDisplayValue

getByDisplayValue, queryByDisplayValue, getAllByDisplayValue, queryAllByDisplayValue, findByDisplayValue, findAllByDisplayValue

API

javascript 复制代码
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 tags

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

const lastNameInput = screen.getByDisplayValue('Norris')


// React
import {render, screen} from '@testing-library/react'

render(<MyComponent />)
const lastNameInput = screen.getByDisplayValue('Norris')

textarea tags

javascript 复制代码
<textarea id="messageTextArea" />

document.getElementById('messageTextArea').value = 'Hello World'
javascript 复制代码
// HTML
import {screen} from '@testing-library/dom'

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


// React
import {render, screen} from '@testing-library/react'

render(<MyComponent />)
const messageTextArea = screen.getByDisplayValue('Hello World')

select tags

如果是select,这将搜索一个匹配给定 TextMatch 的选定<option>的<select>。

html 复制代码
<select>
  <option value="">State</option>
  <option value="AL">Alabama</option>
  <option selected value="AK">Alaska</option>
  <option value="AZ">Arizona</option>
</select>
javascript 复制代码
// HTML
import {screen} from '@testing-library/dom'

const selectElement = screen.getByDisplayValue('Alaska')



// React
import {render, screen} from '@testing-library/react'

render(<MyComponent />)
const selectElement = screen.getByDisplayValue('Alaska')
相关推荐
newxtc7 分钟前
【爱给网-注册安全分析报告-无验证方式导致安全隐患】
前端·chrome·windows·安全·媒体
一个很帅的帅哥23 分钟前
axios(基于Promise的HTTP客户端) 与 `async` 和 `await` 结合使用
javascript·网络·网络协议·http·async·promise·await
dream_ready1 小时前
linux安装nginx+前端部署vue项目(实际测试react项目也可以)
前端·javascript·vue.js·nginx·react·html5
编写美好前程1 小时前
ruoyi-vue若依前端是如何防止接口重复请求
前端·javascript·vue.js
flytam1 小时前
ES5 在 Web 上的现状
前端·javascript
喵喵酱仔__1 小时前
阻止冒泡事件
前端·javascript·vue.js
GISer_Jing1 小时前
前端面试CSS常见题目
前端·css·面试
某公司摸鱼前端1 小时前
如何关闭前端Chrome的debugger反调试
javascript·chrome
八了个戒1 小时前
【TypeScript入坑】什么是TypeScript?
开发语言·前端·javascript·面试·typescript
不悔哥2 小时前
vue 案例使用
前端·javascript·vue.js