`waitFor` utils are not wrapped in `act` so some state updates are not applied to the DOM
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
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/reactversion: 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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của testing-library/react-testing-library
-
fireEvent.select does not wrap its automatic native focus in actCó thể đã có người làm @sergioperezcheco đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict modeCó thể làm lại được @suhailopensource đã nhận 71 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
testing-library/react-testing-library#1466 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
testing-library/react-testing-library#1459 · 2 bình luận ·
-
perf: optimize container lookup with early exitCó thể làm lại được @Ch-Abhinav-Chowdary đã nhận 297 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 35/100
testing-library/react-testing-library#1430 · 1 bình luận ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)Có thể đã có người làm @swarnim02 đã nhận 315 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
Tất cả issue của testing-library/react-testing-library
Issue tương tự
-
ci-install-db-tools stall-case tests flake: stalled apt-get can be killed before it logs its callĐang mởeffort:low model:light plan planner:opus-5-5 tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug 🐞
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mozilla-mobile/firefox-ios#35986 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Hidden loading spinner keeps animating after connect, causing high idle CPU usage in FirefoxĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
bug(sight): the dashboard's text truncations split surrogate pairs and show broken charactersĐang mởcomponent:sight
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
agentic-os-org/ANOLISA#6738 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug Durable Agents Observability (AI Telemetry) status: needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
mastra-ai/mastra#26470 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày