Test based on `findByText` assertion fails after 551ms, despite default timeout being 1000ms
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- javascript, react, typescript
- 領域
- testing-qa
調査の方向性
提示された screen.findByText アサーションと、記載されている @testing-library/react 16.3.0、Vitest 3.2.4、jsdom 26.1.0 のバージョンから始めます。リンク先の findBy ドキュメントと過去の issue をコンテキストとして、失敗がドキュメントに記載された 1000ms のタイムアウトまで到達しているのか、それとも Vitest が所要時間を不正確に報告しているのかを調査します。断続的に発生する早期の失敗の原因を特定するか、それが外部要因であることを記録できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
@testing-library/reactversion: 16.3.0- Testing Framework and version: Vitest 3.2.4
- DOM Environment: jsdom 26.1.0
Relevant code or config:
expect(
await screen.findByText(
"text which is supposed to be found after loading state is passed",
),
).toBeInTheDocument();
What you did:
Ran a test which failed on this assertion. Only sometimes. Typically in CI (Github Actions).
What happened:
× path/to/my.test.tsx > x > shows expected content 551ms
→ expect(element).toBeInTheDocument()
element could not be found in the document
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
FAIL path/to/my.test.tsx > x > shows expected content
Error: expect(element).toBeInTheDocument()
element could not be found in the document
Reproduction:
Does not reproduce easily. Is flaky. Trying to understand if there is some misunderstanding in how things are supposed to work.
Problem description:
When running a test based on findBy, we sometimes find them to be flaky. It is sometimes resolved by using waitForElementToBeRemoved on the previous state, but that just adds another possible race condition, and also tends to be flaky.
I expect the test to run for at least 1000ms (as per findBy logic documented here), but sometimes find that the test fails much sooner (after 551 ms in the example above).
Suggested solution:
I'm trying to deduce a cause here for further investigation.
- Is
findByresolving sooner than expected? If yes, it seems like a problem internal to the library, possibly https://github.com/testing-library/react-testing-library/issues/865? - Is the (vitest) reported time unreliable, and we may have hit the 1000ms timeout despite 551ms being reported? If so, maybe extending the default timeout could be beneficial, even though hundreds of similar tests tend to pass every time, so it seems odd.
Overall, this seems like a strange problem, and I'm not expecting a straight-forward fix, but would like you to know about it, and would be grateful for any pointers on how to analyze further.
- 主要言語
- JavaScript
- スター
- 19.7k
- フォーク
- 1.2k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 が 73 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 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 が 299 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 35/100
testing-library/react-testing-library#1430 · コメント 1 件 ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)対応中かも @swarnim02 が 316 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
testing-library/react-testing-library の issue をすべて見る
似ている issue
-
agent/scanner bug hive/hosted-available-lke648397-260827-5n31
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
rescript-lang/rescript#8765 ·
メンテナーはふだん 1 日以内に返信
-
feedback simulation workshop
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
githubnext/gh-aw-workshop#4417 ·
メンテナーはふだん 1 日以内に返信
-
Good First Issue hacktoberfest
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
hiero-ledger/hiero-sdk-js#4489 ·
メンテナーはふだん 1 日以内に返信
-
Add: RiC Feedオープンcheck:passed feeds:add
難易度 1/5 1時間未満 初心者へのやさしさ 74/100
メンテナーはふだん 9 日以内に返信