Skip to content

Commit f149d81

Browse files
Lei ChenLei Chen
Lei Chen
authored and
Lei Chen
committed
prove wait for works when using useFakeTimers
1 parent ee0b83f commit f149d81

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/dom/__tests__/asyncHook.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,27 @@ describe('async hook tests', () => {
100100

101101
expect(complete).toBe(true)
102102
})
103+
test('should wait for arbitrary expectation to pass when use jest.usedFakeTimers() ', async () => {
104+
jest.useFakeTimers()
105+
106+
const { waitFor } = renderHook(() => null)
107+
108+
let actual = 0
109+
const expected = 1
110+
111+
setTimeout(() => {
112+
actual = expected
113+
}, 200)
114+
let complete = false
115+
jest.advanceTimersByTime(1000)
116+
await waitFor(() => {
117+
expect(actual).toBe(expected)
118+
complete = true
119+
})
120+
121+
expect(complete).toBe(true)
122+
jest.useRealTimers()
123+
})
103124

104125
test('should not hang if expectation is already passing', async () => {
105126
const { result, waitFor } = renderHook(() => useSequence(['first', 'second']))

0 commit comments

Comments
 (0)