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
await userEvent.type causes setState in async effect warns not wrapped in act(...) #424
Comments
Hi @levinqdl, This is expected behavior and has nothing to do with user event and everything to do with what your application is doing as a result of the events that are being fired. To learn more about the act warning read this: https://kentcdodds.com/blog/fix-the-not-wrapped-in-act-warning So what you have with the // this test passes
test('pass', async () => {
render(<App/>)
userEvent.type(screen.getByPlaceholderText('input'), "abc")
// this assertion is available if you're using @testing-library/jest-dom
expect(await screen.findByText('abc')).toBeInTheDocument()
}) I can't think of how we would document it any differently. If your app does something asynchronous, then you should use the async utilities (like |
Hi, @kentcdodds What confused me was since userEvent.type return a promise, so I should always await it. But now it seems await is not good for all cases. So I think it should be documented to remind users about it. |
Just for info |
I'll add a better note in the README about this. |
🎉 This issue has been resolved in version 12.1.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
@testing-library/user-event
version: 12.1.0Relevant code or config
What you did:
testing a compoent with setState in async useEffect
What happened:
test passes with a waning of
not wrapped in act(...)
Reproduction repository:
codesandbox demo: https://codesandbox.io/s/heuristic-chaum-v50nn?file=/src/App.test.js
Problem description:
When await userEvent.type which triggers an async effect to setState another state, the test passes, but a warning of
not wrapped in act(...)
happens.If not await userEvent.type, but use waitFor to assert, no warning happens:
Suggested solution:
I'm not very understand what
act
is doing, and not sure if this is a bug or expected behavior.If it's a bug, the warning should not happen.
If it's expected, this case should be documented. It's very confusing to see the warning.
The text was updated successfully, but these errors were encountered: