You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Other libraries you are using: Not necessary to reproduce, but issue is worse when used with jest and react testing library
What did you expect to happen?
If an interval and multiple timers are all scheduled to execute at the same time, I would expect all of them to execute once, prior to intervals executing again
What actually happens
The interval with a delay of 0 runs repeatedly, and timeouts that are due to run are never executed.
This is especially problematic when used in conjunction with jest and react testing library.
RTL's waitFor method, when used with fake timers, relies on calling an immediate setTimeout and the advancing timers by 0.
If the code under test uses a setInterval with a delay of 0, the test hangs forever. The spec in the reproduction repo demonstrates this without the use of RTL.
Additional Information
In debugging this, it seems that the issue is that when intervals are executed, their callAt time is adjusted by the interval, but their position in the list of timers is not adjusted, so the interval continues to be the first timer to run.
Excellent report! Thanks for taking the time. This seems doable, but I can't do this in the immediate future. Unless you can see a quick fix (which it seemed lik you did) and can supply a PR, I can only say I'll have a look at this in the start of January. Bit busy now just before X-mas :)
What did you expect to happen?
If an interval and multiple timers are all scheduled to execute at the same time, I would expect all of them to execute once, prior to intervals executing again
What actually happens
The interval with a delay of 0 runs repeatedly, and timeouts that are due to run are never executed.
This is especially problematic when used in conjunction with jest and react testing library.
RTL's waitFor method, when used with fake timers, relies on calling an immediate setTimeout and the advancing timers by 0.
If the code under test uses a setInterval with a delay of 0, the test hangs forever. The spec in the reproduction repo demonstrates this without the use of RTL.
How to reproduce
The following code using fake timers
prints
An example without fake timers, such as
prints
Additional Information
In debugging this, it seems that the issue is that when intervals are executed, their callAt time is adjusted by the interval, but their position in the list of timers is not adjusted, so the interval continues to be the first timer to run.
fake-timers/src/fake-timers-src.js
Line 794 in 48f089f
The text was updated successfully, but these errors were encountered: