Filter by description on findByLabel for password input tests
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, react
- 领域
- frontend, testing-qa
调研方向
从 getByLabelText 和 findByLabelText 这两个查询入口开始,然后将它们的行为与 getByRole 中所描述的 description 过滤进行比较。检查 password-input 示例应如何通过其 label 和 aria-describedby 内容进行匹配。对于带 label 的 password inputs,所请求的 description 过滤器能够正常工作且不破坏现有的 label 查询,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Is your feature request related to a problem? Please describe.
I am trying to test that the inputs in my form have correct inline validation errors set as aria descriptions. This works great when the input is simply a textbox:
<Label>
Email
<input type="text' aria-describedby="emailError" />
</Label>
<div id="emailError">Please enter a valid email address</div>
...
expect(findbyRole('textbox', {
name: 'Email',
description: 'Please enter a valid email'
})).toBeInTheDocument();
However, when the input is a password since it has no role I cannot use the description field on getByRole to find the element.
Describe the solution you'd like
This issue recommends using getByLabelText for password inputs, so it would be a lot easier if that query could also search by description.
<Label>
Password
<input type="password' aria-describedby="passwordError" />
</Label>
<div id="passwordError">Please enter your password</div>
...
expect(findByLabelText('Password', {
description: 'Please enter your password'
})).toBeInTheDocument();
Describe alternatives you've considered
Alternatively, if react-testing library could do some magic that means findByRole('password') just works, then that would be a very simple solution and most users probably wouldn't event have to think about it.
For now my tests merely assert that the error exists in the page and ignore the describedby connection.
expect(await screen.findByText('Please enter your new password')).toBeInTheDocument();
Additional context Add any other context or screenshots about the feature
request here.
- 主要语言
- JavaScript
- 星标
- 19.7k
- 派生
- 1.2k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
testing-library/react-testing-library 的其他 Issue
-
fireEvent.select does not wrap its automatic native focus in act可能已有人在做 @sergioperezcheco 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict mode可能重新可做 @suhailopensource 于 77 天前认领,目前没有进行中的 PR。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
testing-library/react-testing-library#1466 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 30/100
testing-library/react-testing-library#1459 · 2 条评论 ·
-
perf: optimize container lookup with early exit可能重新可做 @Ch-Abhinav-Chowdary 于 303 天前认领,目前没有进行中的 PR。 未关闭
难度 1/5 1 小时以内 新手友好度 35/100
testing-library/react-testing-library#1430 · 1 条评论 ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)可能已有人在做 @swarnim02 于 321 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
查看 testing-library/react-testing-library 的全部 Issue
相似的 Issue
-
docs hacktoberfest help wanted
难度 2/5 1-3 小时 新手友好度 85/100
pacocartones/free-llm-api-hub#347 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
cytoscape/cytoscape.js#3536 ·
维护者通常 15 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
cuttle-cards/cuttle#1440 ·
维护者通常 1 天内回复
-
URL-encoded parser builds nested objects nothing reads可能已有人在做 @Senthil455 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 82/100
Janani-bn/CivicFix#168 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
code-yeongyu/oh-my-openagent#10172 ·
维护者通常 1 天内回复