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')
相关推荐
hbstream海之滨视频网络技术几秒前
Google正式上线Gemini In Chrome,国内环境怎样开启。
前端·chrome
Lisson 31 分钟前
VF01修改实际开票数量增强
java·服务器·前端·abap
GISer_Jing4 分钟前
原生HTML项目重构:Vue/React双框架实战
vue.js·人工智能·arcgis·重构·html
微祎_7 分钟前
Flutter for OpenHarmony:构建一个 Flutter 旋转迷宫游戏,深入解析网格建模、路径连通性检测与交互式解谜设计
javascript·flutter·游戏
红色的小鳄鱼11 分钟前
Vue 教程 自定义指令 + 生命周期全解析
开发语言·前端·javascript·vue.js·前端框架·html
coloma201213 分钟前
COCOS代码动态增加刚体和碰撞体的方法
前端·uv
●VON14 分钟前
React Native for OpenHarmony:解构 TouchableOpacity 的触摸反馈与事件流控制
javascript·学习·react native·react.js·性能优化·openharmony
有诺千金17 分钟前
VUE3入门很简单(5)---组件通信(自定义事件)
javascript·vue.js·ecmascript
想逃离铁厂的老铁17 分钟前
Day60 >> 94、城市间货物运输1️⃣ + 95、城市间货物运输 2️⃣ + 96、城市间货物运输 3️⃣
java·服务器·前端
GISer_Jing1 小时前
WebGL跨端兼容实战:移动端适配全攻略
前端·aigc·webgl