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
vi.runAllTicks()
needs to be awaited but isn't "thenable"
#2370
Comments
Well, this is how js works. Promises are resolved as microtasks at the end of the event loop, so if you have a promise like you described, a simple await will work, you can't expect it to be called synchronously. fake timers don’t change how promises work. There is also vi.runAllTicksAsync, maybe you want to use it. There is more documentation about this in sinon docs: https://sinonjs.org/releases/latest/fake-timers/ |
I do think we need a better documentation about the feature though. |
vi.runAllTicks()
needs to be awaited in some casesvi.runAllTicks()
needs to be awaited but isn't thenable
vi.runAllTicks()
needs to be awaited but isn't thenable
vi.runAllTicks()
needs to be awaited but isn't "thenable"
It doesn't need to be awaited. You can achieve the same with: vi.runAllTicks()
await function () {} It just waits until the end of the loop. As far as I know fake timers only work with
|
About the |
Thanks for the explanation. I looked for something like Thanks again for your time! |
To be honest, I don't think you need it here. Fake timers process only |
Yes, that makes sense - awaiting anything would be enough as this is an immediately executed microtask. |
When I only need to await anything to get the microtask queue flushed, I usually do |
Describe the bug
When using
vi.runAllTicks()
, the microtask queue isn't exhausted unless I await the call (await vi.runAllTicks()
) - butrunAllTicks
isn't a promise.I may be doing something else wrong here, but have shared a minimal reproduction.
Reproduction
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: