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')
相关推荐
ZhengEnCi2 小时前
前端日志和后端日志怎么记:分级、JSON 格式、按天分文件与保留策略
前端·后端·python
kyriewen3 小时前
我给 61 个前端库排了两次名,最多差了 46 位
前端·javascript·程序员
亲亲小宝宝鸭4 小时前
Cesium启动:TLE数据是如何变成轨迹线的
前端·cesium
阿里云云原生4 小时前
对话即构建,在 AgentCore 构建 Agent 就是这么简单
前端·agent
夕水4 小时前
我给我的诗写了个后台,顺手写了 一个组件库ew-solid-ui
前端·javascript·typescript
KevinWang_5 小时前
iOS 开发计划(五) - 做一个离线音乐播放器
javascript
狗头大军之江苏分军5 小时前
前端转行干能干什么?我转行试了下(被迫)
前端·后端
孟陬5 小时前
Foobar 技术周刊#2:约会已死?用户急剧下滑,约会App大概率会弱化约会属性转向轻陪伴。我有个建议:
前端·后端·rust
parade岁月6 小时前
VTable Guild 3.0.0 发布,面向 Vue 3 的 ProTable 式业务表格
前端
xurileidian6 小时前
第 17 篇 · 边玩边学Python · for 遍历 enumerate 与 zip
java·前端·python