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
_.debounce() breaks fake timers #2893
Comments
The latest v4 should no longer be breaking fake timers. Dup of #2533. |
I'm still seeing the same issue with it in v4.17.4 of Lodash. I tried it with Jest 18 & 19 on Node 4 & 6. jest.useFakeTimers();
var _ = require('lodash');
test('fails to mock Lodash timers correctly', function() {
var test = jest.fn();
var debounced = _.debounce(test, 1000);
debounced();
debounced();
jest.runAllTimers();
expect(test).toHaveBeenCalledTimes(1);
}); Running that with Jest causes it to say "Ran 100000 timers, and there are still more! Assuming we've hit an infinite recursion and bailing out...". Do you think this is a Lodash issue, or is this something I should pursue on Jest's end? |
Lodash doesn't hold on to references to |
@rimunroe Did you solve your issue somehow? Having a similar problem |
I ended up just avoiding using it, or actually waiting in tests when I absolutely had to. I opened jestjs/jest#3465 about the problem though. |
I believe I know what the problem with Jest is: jestjs/jest#3465 (comment). |
@jdalton so what could we(library consumers) do here? do we need mocking |
@skyboyer I'd go for trying to mock |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
_.debounce() breaks fake timers
In tests, it's common to replace JS timer methods such as
setTimeout
andsetInterval
with fake methods in order to control the passage of time. See Jest Timer Mocks and Sinon Fake Timers. Doing this allows you to march the clock forward in tests, executing all timers synchronously.Recursive calls to
setTimeout
pose a problem when doing this, because the recursivesetTimeout
calls are executed synchronously, causing infinite recursion.The text was updated successfully, but these errors were encountered: