-
Notifications
You must be signed in to change notification settings - Fork 2k
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
tests: migrate fireEvents
to userEvent
where applicable
#63907
Conversation
fd13abf
to
d75f940
Compare
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
d75f940
to
134cc40
Compare
50e64bf
to
97cfcdf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful, thank you ❤️
@@ -170,7 +171,7 @@ describe( '<EligibilityWarnings>', () => { | |||
); | |||
} ); | |||
|
|||
it( `disables the "Continue" button if holds can't be handled automatically`, () => { | |||
it( `disables the "Continue" button if holds can't be handled automatically`, async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this one to be async
if we don't call await
below?
This also raises a question: do all of those here need to be with async / await? I know it's what the library recommends, but the fact that this one passes without it makes me curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the API userEvent
provides is async (methods all return Promises) I think we should await them as the docs say.
In this case, the test passes because we test that handleProceed
doesn't get called in case of a click. As we don't await the click, there may be no click happening at all which also makes the test pass. I'll add a fix and add the missing await
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really great catch by the way 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding an await
makes sense 👍 Thanks for the confirmation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does userEvent.click
really return a promise? Looking at the @testing-library/user-event
internals, I see all functions return void
.
When performing a DOM click, there should be nothing async inside. Internally wrapped with act()
, all React updates happen synchronously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing something, but I can clearly see the click
convenience function returns a Promise<void>
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Release notes for v14 mention that all APIs return Promises https://github.com/testing-library/user-event/releases/tag/v14.0.0 – relevant PR is testing-library/user-event#790 (which closes testing-library/user-event#504), those might contain more in-depth information about that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are both right: we're now using version 13.5.0 which returns void
, and there's version 14.0.x that started returning promises 🙂 The reason for being async is that the library supports firing sequences of events, like when typing a text, with delays between them.
TIL about userEvent! |
97cfcdf
to
f4bfd81
Compare
Changes proposed in this Pull Request
fireEvent
usages to@testing-library/user-event
where applicableTesting instructions
Related to #63409