Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`waitFor` utils are not wrapped in `act` so some state updates are not applied to the DOM

オープン
#1,416 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript, react
領域
frontend, testing

調査の方向性

DOM Testing Library に渡される async wrapper と、App.test.tsx に示されている waitForElementToBeRemoved の使用方法から始めてください。直接的な act 呼び出しを削除したリンク先のコミットを確認し、続いて StackBlitz の再現を使って、明示的な async act がなくても最終的な state update が DOM に適用されることを検証してください。

索引モデルが issue の本文から書いたものです。

説明

  • @testing-library/react version: 16.3.0
  • Testing Framework and version: jest 30.1.3
  • DOM Environment: jsdom 26.1.0
Relevant code or config:
  test('it loads', async () => {
    render(<App />);

    await waitForElementToBeRemoved(screen.queryByRole('progressbar'));
    // Commenting this out fails the test
    // await act(() => new Promise((r) => setTimeout(r, 0)));

    expect(screen.getByText('Loaded')).toBeDefined();
  });
What you did:

Upgrading to React 18 along with react testing library v14, I found that some of my tests were now failing unless I add an explicit async act.

Digging into it, it seems to be this change to the async wrapper passed to the dom testing library where it no longer directly calls act, so state updates from the final iteration of the waitFor are not flushed to the DOM.

It looks like it only flushes the microtask queue, which won't give react an opportunity to process this state update.

Reproduction:

I'm using React 18 and RTL 14 but I've reproduced it on React 19 and RTL 16.

https://stackblitz.com/edit/rtl-template-4a3jt9jx?file=src%2FApp.test.tsx&view=editor

Suggested solution:

I don't have enough knowledge of the codebase to understand why the call to act was removed.

主要言語
JavaScript
スター
19.7k
フォーク
1.2k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

testing-library/react-testing-library のほかの issue

testing-library/react-testing-library の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。