Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

logRoles does not print hidden elements

未关闭
#1,201 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@naorpeled 已经在做这个了。

开始于 2023年6月18日。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
领域
testing-qa

调研方向

从 logRoles 和 logRole 入口点开始,尤其关注 issue 中提到的 TypeScript 签名,并复现包含隐藏元素的空输出。将 role 输出与 screen.debug 进行比较;完成的标准是按要求包含隐藏元素、接受第二个参数,并且相关输出能够区分隐藏元素。

由索引模型根据 Issue 内容生成。

描述

bug
  • @testing-library/react version: 14.0.0
  • Testing Framework and version: Jest 29.4.3
  • DOM Environment: jsdom 29.4.3
Relevant code or config:
const buttons = await waitFor(
    screen.getAllByRole("button", { hidden: true })
);

logRoles(buttons)
What you did:

I was trying to logRoles for a DOM tree with hidden elements. Failed to see the elements show in the roles list.

What happened:

Logging roles for hidden elements produces an empty log.

Reproduction:
  1. Get all elements of a DOM tree including hidden ones. Make sure you have hidden ones.
  2. Log using logRoles
  3. See that some log entries are empty compared to what you see when you screen.debug
Problem description:

If you log an element you found using { hidden: true }, logRoles will not print it. Similarly won't print hidden elements in a DOM tree you pass in. This is the opposite of what I would expect from this tool. I want to know why something may be failing to query, so I want to see everything in the tree.
The logRole function does take a { hidden } parameter and by default is set to false, however the function signature in Typescript does not accept a second parameter.

Suggested solution:

A useful thing would be that hidden was on by default, the function signature would be updated to take the second parameter, and that elements logged that are hidden, report so in the pretty role output.

主要语言
JavaScript
星标
19.7k
派生
1.2k
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

testing-library/react-testing-library 的其他 Issue

查看 testing-library/react-testing-library 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。