Replies: 1 comment
-
I think your issue might be simply due to misconception of promise and async/await. I'm not going to debug your specific function (unless you can simplify it further to show the issue is in Vitest), but hopefully this quick example shows what you might be missing. import { vi, test } from 'vitest';
test('repro', () => {
vi.useFakeTimers();
async function myAsyncFn() {
console.log('x');
await Promise.allSettled([]);
console.log('y');
setTimeout(() => {}, 0);
console.log('z');
}
console.log('1');
myAsyncFn(); // not awaited
console.log('2');
console.log('[vi.getTimerCount()]', vi.getTimerCount());
console.log('3');
});
// this prints
// 1
// x
// 2
// [vi.getTimerCount()] 0
// 3
// y
// z |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi All,
Was hoping someone might see what I'm missing here.
I've written a function to batch and sleep some promises based on some api limits. The function basically batches promises into groups of 20 then executes them. Once the total number of requests hit 240 it will sleep for 1 minute before continuing.
I was expecting the
vi.getTimerCount()
function to return '1' after my function has executed (because its will hit the setTimeout() call, but the test fails sincevi.getTimerCount()
returns 0.Any ideas why?
I've also noticed if i comment out the
const responses = await Promise.allSettled(batch);
line the test passes...This is the error returned when running.
Beta Was this translation helpful? Give feedback.
All reactions