Skip to content

Make "not wrapped in act()" warnings optional #23197

Closed
@anilanar

Description

@anilanar

Problem

My tests do not care about keeping track of every single update (i.e. setState) that happens in a component tree. My tests don't test implementation details. Surely, when and how a component tree updates happen is an implementation detail. In fact, it's sometimes impossible to consider all such implementation details in a relatively big component tree and when using 3rd party libraries. The fact is that majority of tests don't care when and how updates happen.

If a component does only synchronous state updates, it's perhaps not a big deal. You can wrap everything with act (as testing-library does) and move on (well, this statement is partially tongue in cheek).

However, if there are asynchronous state updates, not only it is a hard problem to wrap them with act; sometimes it requires monkey patching the environment (fake timers, fake promises).

Solution

Provide a way to opt-out of such warnings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    React 18Bug reports, questions, and general feedback about React 18Type: Discussion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions