-
Notifications
You must be signed in to change notification settings - Fork 251
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
userEvent.click does not wait for useEffect changes to be flushed #255
userEvent.click does not wait for useEffect changes to be flushed #255
Comments
This is closely related to #128 |
@jessethomson if you wrap userEvent calls with Adding I made a fork of your codesandbox that uses |
Another work around, after doing I dont know, doing this work around has any other side effects. |
This is intended for supporting `act` in React, but should be useful for other frameworks (I think it could help with triggering change detection for angular for example). Ref: testing-library/user-event#188, testing-library/user-event#255, https://github.com/testing-library/user-event/issues/277
This is intended for supporting `act` in React, but should be useful for other frameworks (I think it could help with triggering change detection for angular for example). Ref: testing-library/user-event#188, testing-library/user-event#255, https://github.com/testing-library/user-event/issues/277
Now not only will React Testing Library's `fireEvent` be wrapped in `act`, but so will DOM Testing Library's `fireEvent` (if `@testing-library/react` is imported). It works very similar to async act for the `asyncWrapper` config. Closes: testing-library/user-event#188 Closes: testing-library/user-event#255 Reference: https://github.com/testing-library/user-event/issues/277
🎉 This issue has been resolved in version 10.4.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This is now fixed! |
Scenario
I have a component that executes a callback inside of useEffect any time there is a state change. In my tests, if I use
userEvent.click
to trigger that state change, the callback is executed after my test has already finished and the test fails. If I usefireEvent.click
instead, the test passes.Maybe this is expected and
fireEvent.click
is synchronous anduserEvent.click
is asynchronous and people are just expected to convert all their tests to be async when usinguserEvent
(I hope that's not the case, but maybe I'm missing something).Full disclosure, I don't actually know what the problem is and my understanding of the problem and the title of this issue could be wayyy off.
Example
App.js
App.test.js
Expected
fireEvent.click
foruserEvent.click
should not break tests of components with useEffectActual
fireEvent.click
foruserEvent.click
does break tests of components with useEffectReproduction
The text was updated successfully, but these errors were encountered: