Open History to see the last commit
1import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2import { sleep } from '../sleep'
3β
4describe('sleep', () => {
5 beforeEach(() => {
6 vi.useFakeTimers()
7 })
8β
9 afterEach(() => {
10 vi.useRealTimers()
11 })
12β
13 it('should sleep for the given amount of time', async () => {
14 const onResolve = vi.fn<() => void>()
15β
16 void sleep(100).then(onResolve)
17β
18 await vi.advanceTimersByTimeAsync(99)
19 expect(onResolve).not.toHaveBeenCalled()
20β
21 await vi.advanceTimersByTimeAsync(1)
22 expect(onResolve).toHaveBeenCalledTimes(1)
23 })
24})