Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#1,416 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, react
Lĩnh vực
frontend, testing

Hướng nghiên cứu

Bắt đầu với async wrapper được truyền cho DOM Testing Library và cách sử dụng waitForElementToBeRemoved được thể hiện trong App.test.tsx. Xem lại commit được liên kết đã loại bỏ lệnh gọi act trực tiếp, sau đó sử dụng bản tái hiện StackBlitz để xác minh rằng cập nhật trạng thái cuối cùng được áp dụng vào DOM mà không cần async act tường minh.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

  • @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.

Ngôn ngữ chính
JavaScript
Star
19.7k
Fork
1.2k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của testing-library/react-testing-library

Tất cả issue của testing-library/react-testing-library

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.