Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
@jet2jet

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /