-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
index.test.ts
42 lines (32 loc) · 1.01 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { ref } from 'vue-demi'
import { promiseTimeout } from '../utils'
import { useTimeoutFn } from '.'
describe('useTimeoutFn', () => {
it('supports reactive intervals', async () => {
const callback = vitest.fn()
const interval = ref(0)
const { start } = useTimeoutFn(callback, interval)
start()
await promiseTimeout(1)
expect(callback).toBeCalled()
callback.mockReset()
interval.value = 50
start()
await promiseTimeout(1)
expect(callback).not.toBeCalled()
await promiseTimeout(100)
expect(callback).toBeCalled()
})
it('supports getting pending status', async () => {
const callback = vitest.fn()
const { start, isPending } = useTimeoutFn(callback, 0, { immediate: false })
expect(isPending.value).toBe(false)
expect(callback).not.toBeCalled()
start()
expect(isPending.value).toBe(true)
expect(callback).not.toBeCalled()
await promiseTimeout(1)
expect(isPending.value).toBe(false)
expect(callback).toBeCalled()
})
})