Skip to content

Commit fa84342

Browse files
Lei ChenLei Chen
Lei Chen
authored and
Lei Chen
committed
add runOnlyPendingTimers test
1 parent d80ddd8 commit fa84342

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Diff for: src/dom/__tests__/asyncHook.test.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ 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 () => {
103+
test('should wait for arbitrary expectation to pass when use jest.usedFakeTimers() and advanceTimersByTime() ', async () => {
104104
jest.useFakeTimers()
105105

106106
const { waitFor } = renderHook(() => null)
@@ -112,7 +112,31 @@ describe('async hook tests', () => {
112112
actual = expected
113113
}, 200)
114114
let complete = false
115-
jest.advanceTimersByTime(1000)
115+
jest.advanceTimersByTime(200)
116+
await waitFor(
117+
() => {
118+
expect(actual).toBe(expected)
119+
complete = true
120+
},
121+
{ timeout: 250, interval: 10 }
122+
)
123+
124+
expect(complete).toBe(true)
125+
jest.useRealTimers()
126+
})
127+
test('should wait for arbitrary expectation to pass when use jest.usedFakeTimers() and runOnlyPendingTimers() ', async () => {
128+
jest.useFakeTimers()
129+
130+
const { waitFor } = renderHook(() => null)
131+
132+
let actual = 0
133+
const expected = 1
134+
135+
setTimeout(() => {
136+
actual = expected
137+
}, 200)
138+
let complete = false
139+
jest.runOnlyPendingTimers()
116140
await waitFor(
117141
() => {
118142
expect(actual).toBe(expected)

0 commit comments

Comments
 (0)