getByText not working for multiline text
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, react
- 领域
- testing-qa
调研方向
使用 getByText 查询入口重现失败和通过的 JavaScript 示例。issue 模板将查询 API 工作指向 dom-testing-library 仓库,因此应从那里开始,而不是从此 React 仓库开始。当多行 getByText 断言成功,同时保留通过的单行行为时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
@testing-library/reactversion: 13.3.0- Testing Framework and version:[email protected]
- DOM Environment:[email protected] jest-environment-jsdom@^27.5.1
Using multiline text in getByText fails. Is there a workaround for this?
Failing test
const exampleText = `
hello
world
`
const textElement = screen.getByText(
exampleText.slice(0, 10),
{ exact: false }
);
console.info(textElement.textContent === exampleText); // == True
expect(screen.getByText(exampleText)).toBeInTheDocument(); // == Fail
Passing test
const exampleText = `hello world`
const textElement = screen.getByText(
exampleText.slice(0, 10),
{ exact: false }
);
console.info(textElement.textContent === exampleText); // == True
expect(screen.getByText(exampleText)).toBeInTheDocument(); // == Pass
- 主要语言
- 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 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict mode可能重新可做 @suhailopensource 于 72 天前认领,目前没有进行中的 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 于 298 天前认领,目前没有进行中的 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 于 315 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
查看 testing-library/react-testing-library 的全部 Issue
相似的 Issue
-
[BUG] Multi-day events show "Ended" while still in progress可能已有人在做 @tarunagnihotri534 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 85/100
data-umbrella/du-event-board#231 · 2 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 65/100
NaturalIntelligence/fast-xml-parser#888 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 80/100
USACE/chart-docs#766 ·
-
bug callouts regression revealjs
难度 2/5 1-3 小时 新手友好度 72/100
quarto-dev/quarto-cli#15014 ·
维护者通常 1 天内回复