File tree 1 file changed +10
-4
lines changed
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { waitFor , waitForElementToBeRemoved } from '..'
2
2
import { render } from './helpers/test-utils'
3
3
4
- async function runWaitFor ( { time = 300 } = { } , options ) {
4
+ async function runWaitFor ( { time = 300 , advanceTimers = true } = { } , options ) {
5
5
const response = 'data'
6
6
const doAsyncThing = ( ) =>
7
7
new Promise ( r => setTimeout ( ( ) => r ( response ) , time ) )
8
8
let result
9
9
doAsyncThing ( ) . then ( r => ( result = r ) )
10
-
10
+ if ( advanceTimers ) {
11
+ jest . advanceTimersByTime ( time )
12
+ }
11
13
await waitFor ( ( ) => expect ( result ) . toBe ( response ) , options )
12
14
}
13
15
16
+ afterEach ( ( ) => {
17
+ jest . useRealTimers ( )
18
+ } )
19
+
14
20
test ( 'real timers' , async ( ) => {
15
21
// the only difference when not using fake timers is this test will
16
22
// have to wait the full length of the timeout
17
- await runWaitFor ( )
23
+ await runWaitFor ( { advanceTimers : false } )
18
24
} )
19
25
20
26
test ( 'legacy' , async ( ) => {
@@ -23,7 +29,7 @@ test('legacy', async () => {
23
29
} )
24
30
25
31
test ( 'modern' , async ( ) => {
26
- jest . useFakeTimers ( )
32
+ jest . useFakeTimers ( 'modern' )
27
33
await runWaitFor ( )
28
34
} )
29
35
You can’t perform that action at this time.
0 commit comments