Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
anilanar opened this issue Jan 27, 2022 · 2 comments
Closed

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

anilanar opened this issue Jan 27, 2022 · 2 comments
Labels
React 18 Bug reports, questions, and general feedback about React 18 Type: Discussion

Comments

@anilanar
Copy link

anilanar commented Jan 27, 2022

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.

@anilanar anilanar added React 18 Bug reports, questions, and general feedback about React 18 Type: Discussion labels Jan 27, 2022
@salazarm
Copy link
Contributor

salazarm commented Feb 9, 2022

set global.IS_REACT_ACT_ENVIRONMENT = false

@eps1lon
Copy link
Collaborator

eps1lon commented Mar 20, 2022

set global.IS_REACT_ACT_ENVIRONMENT = false

For more information, check the working group thread about global.IS_REACT_ACT_ENVIRONMENT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
React 18 Bug reports, questions, and general feedback about React 18 Type: Discussion
Projects
None yet
Development

No branches or pull requests

3 participants