Is wrapping with act now required? #906
-
I have updated to React 18 and now to see a lot of act warnings and have needed to manually wrap userEvent calls. This is also the first time we have updated to userEvent 14, so perhaps we are doing something wrong? I have tried using the convenience API and also a 'session' I have created a simple test case with attached screenshot and code - test 1 has no warnings, but tests 2 and 3 do:
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 4 replies
-
Some further explorations:
|
Beta Was this translation helpful? Give feedback.
-
No, wrapping with
If
|
Beta Was this translation helpful? Give feedback.
-
Thanks, since my last comment I have started with a fresh install which does not exhibit this act warning. I have a feeling we have some kind of package mismatch somewhere - we have a quite large Monorepo. |
Beta Was this translation helpful? Give feedback.
-
What fixed it for us in our monorepo was to set the resolution in our root package.json:
|
Beta Was this translation helpful? Give feedback.
-
I had the same issue, and I found that the root cause is having multiple versions of Do a User event registers an internal wrapper named |
Beta Was this translation helpful? Give feedback.
-
I had the same problem, and I found upgrading to @testing-library/[email protected] resolved the issue. |
Beta Was this translation helpful? Give feedback.
-
The fix for my case was described in the answer (which was taken from the docs)
So I just removed |
Beta Was this translation helpful? Give feedback.
No, wrapping with
act
is neither required nor recommended.@testing-library/react
manipulates the configuration of the underlying@testing-library/dom
when you import it.@testing-library/user-event
uses that configuration.If
await user.anyAPI()
yields anact
warning anduser.anyAPI(); await waitFor()
does not, they might not use the same configuration i.e. not the same copy of@testing-library/dom
.