Skip to content

Commit 51fd8e7

Browse files
committed
test: enable modern timers test
1 parent ffc8f26 commit 51fd8e7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/__tests__/fake-timers.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import {waitFor, waitForElementToBeRemoved} from '..'
22
import {render} from './helpers/test-utils'
33

4-
async function runWaitFor({time = 300} = {}, options) {
4+
async function runWaitFor({time = 300, advanceTimers = true} = {}, options) {
55
const response = 'data'
66
const doAsyncThing = () =>
77
new Promise(r => setTimeout(() => r(response), time))
88
let result
99
doAsyncThing().then(r => (result = r))
10-
10+
if (advanceTimers) {
11+
jest.advanceTimersByTime(time)
12+
}
1113
await waitFor(() => expect(result).toBe(response), options)
1214
}
1315

16+
afterEach(() => {
17+
jest.useRealTimers()
18+
})
19+
1420
test('real timers', async () => {
1521
// the only difference when not using fake timers is this test will
1622
// have to wait the full length of the timeout
17-
await runWaitFor()
23+
await runWaitFor({advanceTimers: false})
1824
})
1925

2026
test('legacy', async () => {
@@ -23,7 +29,7 @@ test('legacy', async () => {
2329
})
2430

2531
test('modern', async () => {
26-
jest.useFakeTimers()
32+
jest.useFakeTimers('modern')
2733
await runWaitFor()
2834
})
2935

0 commit comments

Comments
 (0)