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

On jest, `afterEach(cleanup)` is too late to unmount a component using `useSyncExternalStore` with asynchronous updating

Đang mở
#1,421 1 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
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
javascript, react
Lĩnh vực
frontend, testing-qa

Hướng nghiên cứu

Bắt đầu bằng cách chạy repository tái hiện được liên kết trong issue với Jest, React và @testing-library/react. Điều tra timing giữa lúc test kết thúc và afterEach(cleanup), tập trung vào cách các bản cập nhật useSyncExternalStore được xử lý trong khi unmount. Được xem là hoàn tất khi reproduction không còn ghi lại cảnh báo act trong cleanup và hành vi hiện có vẫn được giữ nguyên.

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
  • react version: 19.2.0
  • Testing Framework and version:
    • jest: 30.2.0
  • DOM Environment:
    • jsdom: 27.0.1
Relevant code or config:

None (please see reproduction repository described below)

What you did:

Testing a component using React's useSyncExternalStore and running the test without async

What happened:

useSyncExternalStore's update may happen just after finishing the test, but afterEach is not called in that timing, so the callback of useSyncExternalStore cannot handle 'unmounted' state, resulting the log An update to TestComponent inside a test was not wrapped in act(...)..

Reproduction:

I created a repositoy for the reproduction: https://github.com/jet2jet/testing-test

Problem description:

During just after finishing a test and just before afterEach, the test code cannot insert act() calls, so the problem An update to ... cannot be resolved with using act().

Suggested solution:

I think it's very difficult to call cleanup() just after finishing a test, but it's necessary to unmount, for resolving timing problem.

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.