-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
[code-infra] Optimize @testing-library/user-event
#43804
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -301,7 +301,7 @@ function render( | |
| ); | ||
| const result: MuiRenderResult = { | ||
| ...testingLibraryRenderResult, | ||
| user: userEvent.setup(), | ||
| user: userEvent.setup({ delay: null }), | ||
|
||
| forceUpdate() { | ||
| traceSync('forceUpdate', () => | ||
| testingLibraryRenderResult.rerender( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Going off topic, but would this works instead?
Uh oh!
There was an error while loading. Please reload this page.
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 think you want to initialize it per test. At least that's seems to be recommended on their docs. I understand the instance hold state and you can avoid interference between parallel tests this way.
Uh oh!
There was an error while loading. Please reload this page.
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 what I'm not clear about. In the source, I didn't see logic that required it to be initialized once for all the tests, this would save CI time for each test and make the DX simpler as well.
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.
Not sure I follow @oliviertassinari. I think we should just follow the Testing Lib recommendation here i.e. setup userEvent once per test.
Uh oh!
There was an error while loading. Please reload this page.
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 have found testing-library/user-event#1036 (comment) about this. It could be ok
https://github.com/testing-library/user-event/blob/d0362796a33c2d39713998f82ae309020c37b385/src/setup/setup.ts#L82.
prepareDocumentbails out if it's already called. https://github.com/testing-library/user-event/blob/d0362796a33c2d39713998f82ae309020c37b385/src/document/prepareDocument.ts#L19attachClipboardStubToViewbails out if it's already called. https://github.com/testing-library/user-event/blob/d0362796a33c2d39713998f82ae309020c37b385/src/utils/dataTransfer/Clipboard.ts#L113So I don't really see why it's needed in our case since we share the same document between tests.
But no hard point of view. Just that if we want to be greedy, there is maybe an opportunity, but maybe not.
Uh oh!
There was an error while loading. Please reload this page.
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.
With Vitest, the need to have a document always setup for each test could become an issue, depending on how parallelism is implemented. I imagine that it's OK, but it might not.