-
Notifications
You must be signed in to change notification settings - Fork 252
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.type's delay hangs forever #565
Comments
Could you reproduce the bug in a sandbox ? |
Yeah, that's what I should have done in the first place. In a small sample I might even find my configuration mistake :-) Will reply with an update once I know one way or the other. |
i have the same issue |
I solve the issue by setting real timers of jest before the type. Hope it helps 😄
|
If I could get back all the time I've wasted chasing defects caused by jest's replacement of standard Javascript functions... That solved my issue as well. Thanks! |
I'm glad your problem is solved. To add some more information about relationship of timers and Line 124 in 7a5c51e
Each block of events for a character is delayed per If you want to use real timers for some part of your code, there is also this solution by import { runWithRealTimers } from '@testing-library/dom/dist/helpers'
runWithRealTimers(() => {
// do something with real timers
})
// do something with the timers you had in place before - real or fake If you don't like to use an internal but also don't want to repeat the code, open an issue there. Maybe adding this to the exports of the main module is worth a discussion. :) |
I just got my test worked via this issue! thx a lot for detailed comment :) |
Ran into this issue while writing a test with a large character count in an input field that had to be async; |
Please note that If you have mocked the timer functions by other means than |
Thanks for the follow-up @ph-fritsche -- I would like to solve this properly in the future but
|
@ph-fritsche - Would it be possible to add an As an example of the approach, I'm using this "wrapper" around type (it only works for plaintext):
So instead of above, I could just call |
Actually this would be really cool, to advance timers. It could remove instabilities that could appear for waiting the type function. |
Just incurred in something similar while writing tests with version Basically, the Line 124 in 7a5c51e
(cc @ph-fritsche ) |
I'm seeing the similar instability in Sometimes multiple tests timeout, sometimes none do. Setting the delay to |
|
* ci(github-actions): run all tests on PR to develop * test(frontend): fix outdated frontend test * test(frontend): fix issue with userEvent timing out test cases More info testing-library/user-event#565 (comment) * test(frontend): add back tests for protected email template
Thank you for the update, @ph-fritsche — although I still don't understand how the Thank you! |
We push user-event/src/utils/misc/wait.ts Lines 3 to 12 in ee062e7
E.g. with Jest's fake timers: jest.useFakeTimers()
const user = userEvent.setup({advanceTimers: jest.advanceTimersByTime})
await user.type(element, 'foo') |
Up front...
This issue probably belongs in angular-testing-library, jest-preset-angular, or maybe jest-dom, but I can't say where at the moment, and the problem is manifest in user-event .
Also, there is may be a better title depending on where this belongs.
Please feel free to modify any of this or redirect me as appropriate.
@testing-library/user-event
version: 12.7.3Testing Framework and version:
jest: 26.6.3
angular: 11.2.2
node: 12.18.4
jest-dom: 5.11.9
angular-testing-library: 10.3.2
jest-preset-angular: 8.3.2
Relevant code or config
My jest test simulates the user clicking an input, and clearing it's existing text:
What happened:
If
delay
is set to zero the test passes as expected.If
delay
is greater than zero, the test hangs until jest times out (longer jest timeout does not help).What you did:
user-event/src/type.js currently contains the following code:
A breakpoint on
if (delay > 0)
is always hit.A breakpoint on
if (!currentElement().disabled)
is never hit (assuming you call with delay > 0).What I tried:
Disabling the zone.js patch of setTimeout allows the test to pass (although obviously not a real solution).
Problem description:
This issue seems like an interaction problem between packages in the testing-library ecosystem. I've followed each packages installation and setup guides, and believe my import ordering and configurations are correct, but obviously something was missed somewhere.
Any suggestions?
The text was updated successfully, but these errors were encountered: