Skip to content

Commit

Permalink
fix(useInterval): 修复测试问题
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Jul 21, 2020
1 parent 5402739 commit 7688b13
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/react/useInterval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('useInterval', () => {
expect(result.current[0]).toBe(1)
result.current[1].start()
expect(result.current[0]).toBe(2)
await wait(20)
await wait(25)
expect(result.current[0]).toBe(3)
})

Expand All @@ -26,15 +26,15 @@ describe('useInterval', () => {
return { interval: useInterval(() => i++, delay), setDelay }
})
expect(result.current.interval[0]).toBe(0)
await wait(20)
await wait(25)
expect(result.current.interval[0]).toBe(1)
act(() => result.current.setDelay(false))
await wait(40)
expect(result.current.interval[0]).toBe(1)
act(() => result.current.setDelay(20))
await wait(0)
expect(result.current.interval[0]).toBe(2)
await wait(20)
await wait(25)
expect(result.current.interval[0]).toBe(3)
})

Expand All @@ -53,11 +53,9 @@ describe('useInterval', () => {
return useInterval(() => i++, null)[1]
})
expect(i).toBe(0)
act(() => result.current.start(10, 42))
act(() => result.current.start(10, 3))
expect(i).toBe(1)
await wait(12)
expect(i).toBe(2)
await wait(60)
expect(i).toBe(4)
expect(i).toBe(1)
})
})

0 comments on commit 7688b13

Please sign in to comment.