Warning 'An update inside a test was not wrapped in act(...)' while testing with React Testing Library #4232
Replies: 6 comments 32 replies
-
hey @antoine-coulebaud this is mostly due to async validation. you will need to wrap with |
Beta Was this translation helpful? Give feedback.
-
I'm dealing with this as well. My understanding is the |
Beta Was this translation helpful? Give feedback.
-
My issue is when I wrap the fireEvent with the act, it solves the warning, but then I get the following Eslint error: My code: await act(async () => {
fireEvent.change(screen.getByLabelText("Email"), {
target: { value: "validEmail@yopmail.com" },
}); My test verifies if the error is not in the document, and the waitFor solution does not work for me. |
Beta Was this translation helpful? Give feedback.
-
await act(async () => {
render(<MyComponent/>, {
wrapper: Wrapper,
});
}); Add |
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 @Belco90 hi there folks, thank you for the docs on testing, they really helped 🙏 I'm still seeing the I have a reproducible example in this CodeSandbox link
to
is there any recommended workaround for this scenario? |
Beta Was this translation helpful? Give feedback.
-
Having the same issue when using React Hook Form with a Select component in Radix UI. If my form has either a Select or a TextInput , everything works like a charm. I'm using the latest user-event library and awaiting all user actions. But if I have both a TextInput and a Select, I get the famous warning. Here are my two workarounds:
I cannot understand why these workarounds work. Can anyone explain it to me? |
Beta Was this translation helpful? Give feedback.
-
Hi
I wanted to test some of my react-hook-form components with react-testing-libray.
While some of my tests seems to pass as expected, the warning
An update inside a test was not wrapped in act(...)
pops and I can't figure why. I tried to reduce the code to the minimum in ordre to reproduce, and rewrite it in a sandbox (https://codesandbox.io/s/adoring-lamarr-xxxnj) but infortunately an other error occurred and I can't retrieve the exact same warning as in my own repo.Can you tell me :
Thanks
Beta Was this translation helpful? Give feedback.
All reactions