@@ -3,7 +3,12 @@ import { act } from './act';
33import { getConfig } from './config' ;
44import { flushMicroTasks } from './flush-micro-tasks' ;
55import { copyStackTrace , ErrorWithStack } from './helpers/errors' ;
6- import { clearTimeout , jestFakeTimersAreEnabled , setTimeout } from './helpers/timers' ;
6+ import {
7+ clearTimeout ,
8+ getJestFakeTimersType ,
9+ jestFakeTimersAreEnabled ,
10+ setTimeout ,
11+ } from './helpers/timers' ;
712import { wrapAsync } from './helpers/wrap-async' ;
813
914const DEFAULT_INTERVAL = 50 ;
@@ -36,9 +41,9 @@ function waitForInternal<T>(
3641
3742 let overallTimeoutTimer : NodeJS . Timeout | null = null ;
3843
39- const usingFakeTimers = jestFakeTimersAreEnabled ( ) ;
44+ const fakeTimersType = getJestFakeTimersType ( ) ;
4045
41- if ( usingFakeTimers ) {
46+ if ( fakeTimersType ) {
4247 checkExpectation ( ) ;
4348 // this is a dangerous rule to disable because it could lead to an
4449 // infinite loop. However, eslint isn't smart enough to know that we're
@@ -70,7 +75,11 @@ function waitForInternal<T>(
7075 // third party code that's setting up recursive timers so rapidly that
7176 // the user's timer's don't get a chance to resolve. So we'll advance
7277 // by an interval instead. (We have a test for this case).
73- await act ( ( ) => jest . advanceTimersByTime ( interval ) ) ;
78+ await act ( ( ) =>
79+ fakeTimersType === 'modern'
80+ ? jest . advanceTimersByTimeAsync ( interval )
81+ : jest . advanceTimersByTime ( interval ) ,
82+ ) ;
7483
7584 // It's really important that checkExpectation is run *before* we flush
7685 // in-flight promises. To be honest, I'm not sure why, and I can't quite
@@ -96,7 +105,7 @@ function waitForInternal<T>(
96105 clearTimeout ( overallTimeoutTimer ) ;
97106 }
98107
99- if ( ! usingFakeTimers ) {
108+ if ( ! fakeTimersType ) {
100109 clearInterval ( intervalId ) ;
101110 }
102111
0 commit comments