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')
相关推荐
小鲤鱼ya2 分钟前
vue3 + ts + uni-app 移动端封装图片上传添加水印
前端·typescript·uni-app·vue3
霍理迪4 分钟前
Vue—条件渲染与循环渲染
前端·javascript·vue.js
xixixin_8 分钟前
【CSS】字体大小不一致?px与vw渲染差异的底层原理与解决方案
前端·css
zhen_hong11 分钟前
ReactAgent原理
android·java·javascript
小J听不清13 分钟前
CSS 内边距(padding)全解析:取值规则 + 表格实战
前端·javascript·css·html·css3
zhangjikuan8914 分钟前
在 ArkTS 中,Promise 的使用比 TypeScript 更严格(必须显式指定泛型类型)
前端·javascript·typescript
桐溪漂流14 分钟前
Uni-app H5 环境下 ResizeObserver 监听 mp-html 动态高度
前端·uni-app·html
Highcharts.js16 分钟前
React 如何实现大数据量图表(性能优化指南)
前端·javascript·react.js·信息可视化·集成·highcharts
奔跑的呱呱牛17 分钟前
如何设计一个可扩展的地图前端架构?从0到1的工程实践(OpenLayers)
前端·架构·openlayers