Skip to content

Commit

Permalink
add runOnlyPendingTimers test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lei Chen authored and Lei Chen committed Jun 18, 2021
1 parent d80ddd8 commit fa84342
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/dom/__tests__/asyncHook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('async hook tests', () => {

expect(complete).toBe(true)
})
test('should wait for arbitrary expectation to pass when use jest.usedFakeTimers() ', async () => {
test('should wait for arbitrary expectation to pass when use jest.usedFakeTimers() and advanceTimersByTime() ', async () => {
jest.useFakeTimers()

const { waitFor } = renderHook(() => null)
Expand All @@ -112,7 +112,31 @@ describe('async hook tests', () => {
actual = expected
}, 200)
let complete = false
jest.advanceTimersByTime(1000)
jest.advanceTimersByTime(200)
await waitFor(
() => {
expect(actual).toBe(expected)
complete = true
},
{ timeout: 250, interval: 10 }
)

expect(complete).toBe(true)
jest.useRealTimers()
})
test('should wait for arbitrary expectation to pass when use jest.usedFakeTimers() and runOnlyPendingTimers() ', async () => {
jest.useFakeTimers()

const { waitFor } = renderHook(() => null)

let actual = 0
const expected = 1

setTimeout(() => {
actual = expected
}, 200)
let complete = false
jest.runOnlyPendingTimers()
await waitFor(
() => {
expect(actual).toBe(expected)
Expand Down

0 comments on commit fa84342

Please sign in to comment.