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

post-upgrade, unexpected assertion failures on error-handling function calls (includes repro)

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

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
javascript, react
领域
frontend, testing

调研方向

从链接的 CRA 复现开始,检查 issue 中所示的 render、findByText 和 mockLog 断言顺序。确认升级后的时序行为,并记录为什么等待渲染出的错误并不能证明基于 effect 的日志调用已经完成。

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

描述

Relevant code or config:
  render(<App />);

  await screen.findByText('Failed!');

  //assertion fails unless we `waitFor` it
  expect(mockLog).toHaveBeenCalledWith('kaboom!')
What you did:

Upgraded existing application to react 18+ and RTL 13+.

What happened:

A number of tests starting failing assertions after upgrading.

In this case, the component is rendered with a simulated fetch failure. The component renders a child component that is responsible for error presentation and minor logging (in an effect hook). The test assertion on the logging function call fails unless it is awaited.

Reproduction:

I was able to reproduce the issue with a simple CRA repo, here: https://github.com/trv-wcaneira/fetch-err-waitfor-mcve

Problem description:

Pre-upgrade, it was sufficient to await the error message text rendered by the child component. Now it seems additional waiting is needed, and before I plaster waitFors all over our tests 😄, I'd just like to understand why.

Suggested solution:

I could obviously change all the tests to waitFor the logging function call, but would like to understand the change in behavior.

主要语言
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 摘要。