File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,8 +49,8 @@ export async function sleepUntil(
4949 }
5050
5151 // Wait for condition to pass
52- const start = Date . now ( ) ;
53- while ( Date . now ( ) - start < maxDuration ) {
52+ const start = realNow ( ) ;
53+ while ( realNow ( ) - start < maxDuration ) {
5454 await sleep ( pollInterval ) ;
5555 if ( condition ( ) ) {
5656 // Success
@@ -100,8 +100,17 @@ function realNow() {
100100 * offset.
101101 */
102102export function setupFakeTimers ( ) {
103- beforeEach ( ( ) => void jest . useFakeTimers ( ) ) ;
104- afterEach ( ( ) => void jest . useRealTimers ( ) ) ;
103+ let interval : ReturnType < typeof setInterval > | null = null ;
104+ beforeEach ( ( ) => {
105+ interval = setInterval ( ( ) => {
106+ jest . advanceTimersByTime ( 0 ) ;
107+ } , 10 ) ;
108+ jest . useFakeTimers ( ) ;
109+ } ) ;
110+ afterEach ( ( ) => {
111+ void jest . useRealTimers ( ) ;
112+ if ( interval != null ) clearInterval ( interval ) ;
113+ } ) ;
105114
106115 /**
107116 * Sets the fake time such that a call to `Date.now()` (or `new Date()`)
You can’t perform that action at this time.
0 commit comments