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')
相关推荐
Bingo_BIG6 分钟前
甘特图 dhtmlxGantt.js UA实例
javascript·甘特图·ua
编程乐学(Arfan开发工程师)29 分钟前
28、请求处理-【源码分析】-请求映射原理
java·前端·spring boot·后端·spring
咔咔库奇35 分钟前
前端开源JavaScrip库
前端·开源
_r0bin_1 小时前
前端面试准备2
前端·html
白皎1 小时前
立志成为一名优秀测试开发工程师(第九天)——使用fiddler工具、request库进行接口测试
前端·python·fiddler
召田最帅boy1 小时前
基于URL弹窗的图片链接生成功能技术实现
android·java·javascript
saadiya~1 小时前
Vue3 + Element Plus 实现树形结构的“单选 + 只选叶子节点 + 默认选中第一个子节点”
前端·javascript·vue.js
方圆工作室1 小时前
HTML5 Canvas 星空战机游戏开发全解析
前端·html·html5
正函数1 小时前
HTML5有那些更新
前端·html·html5
zhutoutoutousan2 小时前
基于React和TypeScript的金融市场模拟器开发与模式分析
前端·人工智能·react.js·金融·typescript·机器人·自动化