You mock the clock, advance it, and assert. The assertion runs before the code under test has finished.
async function poll() {
await new Promise((r) => setTimeout(r, 1000))
return 'done'
}
advanceTimersByTime moves the clock but not the microtask queue. That mismatch is why your timer test hangs on a promise that never settles.
You mock the clock, advance it, and assert. The assertion runs before the code under test has finished.
async function poll() {
await new Promise((r) => setTimeout(r, 1000))
return 'done'
}

Every (or at least a lot of) project seems to have code like this somewhere: if...

You've written retry logic. It probably looks something like this: async function withRetry(fn,...

TL;DR: setTimeout(fn, 0) doesn't run code instantly — it defers execution to the Macrotask queue,...

I built Temporize because traditional debounce/throttle utilities don’t compose particularly well...

Here's a Playwright test that looks completely reasonable and silently lies to...

The test hung for 30 seconds. The response had already fired. One moved line fixed it. The test hung...