-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
Problem with useFakeTimers: Promise are freeze when resolve it from setTimeout #1397
Comments
Hi @qoter, thanks for your issue 😄 I believe this happens because you either gotta use a timer from the This is one of the possible fixes for your test: let clock = fakeTimers.useFakeTimers();
let p = Promise.resolve()
.then(() => new Promise(resolve => fakeTimers.timers.setTimeout(resolve, 5)));
clock.tick(1000);
return p; The other one, using |
Hello @lucasfcosta))) Examples:
let clock = lolex.install();
let p = Promise.resolve()
.then(() => new Promise(resolve => lolex.timers.setTimeout(resolve, 5)));
clock.tick(1000);
return p;
let clock = lolex.install();
let p = Promise.resolve()
.then(() => new Promise(resolve => setTimeout(resolve, 5)));
clock.tick(1000);
return p;
let clock = lolex.install();
let p = new Promise(resolve => setTimeout(resolve, 5));
clock.tick(1000);
return p; I really do not understand why this happens. |
Has this stalled? |
@mroderick |
Are you using any Promise libraries? They often use timers to create polyfills, which might be affected by faking time. |
@fatso83 No, I use default Promise from node.js |
+1 I'm having this issue too. Just using native Promise |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
+1 I'm having this issue too. |
We should probably move this to lolex, to get it fixed. |
This issue was moved to sinonjs/fake-timers#194 |
Code example
I expect that test will pass.
But test fail with timeout and promise are frozen.
Without sinon.useFakeTimers() this test will pass.
The text was updated successfully, but these errors were encountered: