Skip to content

Commit

Permalink
fix: also run microtasks after async pending timers
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Sep 6, 2024
1 parent 5534d02 commit 08212a1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/jest.timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ export function advanceTimersByTime(time) {
}

export async function runAllTimersAsync() {
await awaitForMicrotaskQueue() // only once, before running timers, per jest doc
await awaitForMicrotaskQueue() // before running timers, per jest doc
runAllTimers()
await awaitForMicrotaskQueue() // jest doc is misleading and it also does this after running timers
return this
}

export async function runOnlyPendingTimersAsync() {
await awaitForMicrotaskQueue() // only once, before running timers, per jest doc
await awaitForMicrotaskQueue() // before running timers, per jest doc
runOnlyPendingTimers()
await awaitForMicrotaskQueue() // jest doc is misleading and it also does this after running timers
return this
}

Expand All @@ -89,6 +91,7 @@ export async function advanceTimersByTimeAsync(time) {
}
}

await awaitForMicrotaskQueue() // jest doc is misleading and it also does this after running timers
return this
}

Expand Down

0 comments on commit 08212a1

Please sign in to comment.