Fix async timing in tests using user-event#40790
Conversation
await in front of user typing events in Unit Control testsawait for user interactions during unit tests
await for user interactions during unit tests|
Gotta |
…ove unnecessary `waitFor`
3e9a61d to
79bdd56
Compare
user-event
|
Size Change: -14 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
| // TODO: investigate why `onChange` gets called twice instead of once | ||
| expect( onChangeSpy ).toHaveBeenCalledTimes( 2 ); |
There was a problem hiding this comment.
This is the only diverging test — although I don't think it should block this PR from being merged, as it's a behavior that can be currently reproduced in trunk
There was a problem hiding this comment.
I agree.
// TODO: investigate whyonChangegets called twice instead of once
I guess it's been that way for quite some time now and somehow the async oversights in the test suite were masking it. We could look at extracting this change(and your added code comment) from #40568 to a separate PR.
There was a problem hiding this comment.
Sounds like a plan! Opened #40796 with those changes
stokesman
left a comment
There was a problem hiding this comment.
Superbly done! It's great to see the update with user-event’s advanceTimers and the cleanup of the waitFors (which I guess had been necessary due to missing awaits in other places).
The only thing I noticed was the typo of “trigger” (x3)
| ...RTLrender( jsx ), | ||
| }; | ||
| } | ||
| const user = userEvent.setup( { |
There was a problem hiding this comment.
@testing-library recommends that setup() is called inline once per test.
https://testing-library.com/docs/user-event/intro#writing-tests-with-userevent
There was a problem hiding this comment.
I must have missed that part when looking at the new v14 docs, thank you for flagging it! Opened #40839 as a follow-up with those changes
What?
Polish/improve unit tests using
@testing-library/user-eventby making sure that weawaiteach user interaction properly.Why?
As part of the investigation around fixing a timeout error when using
@testing-library/user-event(comment), and related to the recent conversations in #40568 (comment) and #40697 (comment)How?
this PR applies a few small tweaks to the unit tests of
UnitControlandFormFileUpload. Most notable changes are:@testing-library/user-eventfunctions are now prefixed withawaitjest.fakeTimers(as suggested here)waitForcalls (not needed anymore)Testing Instructions
Review code changes, and make sure that all tests pass.