Skip to content

Commit 8887119

Browse files
committed
test: use-lock-fn
1 parent 0551106 commit 8887119

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import useBoolean from '@/useBoolean'
2+
import { sleep } from '@/utils/sleep'
3+
import { ref } from 'vue'
4+
import useLockFn from '..'
5+
6+
describe('useLockFn', () => {
7+
const countRef = ref(0)
8+
const [tag, { set: updateTag }] = useBoolean(false)
9+
10+
const fn = async (step: number) => {
11+
countRef.value += step
12+
await sleep(50)
13+
}
14+
const locked = useLockFn(fn)
15+
16+
it('should work', async () => {
17+
locked(1)
18+
expect(countRef.value).toBe(1)
19+
locked(2)
20+
expect(countRef.value).toBe(1)
21+
await sleep(30)
22+
locked(3)
23+
expect(countRef.value).toBe(1)
24+
await sleep(30)
25+
locked(4)
26+
expect(countRef.value).toBe(5)
27+
locked(5)
28+
expect(countRef.value).toBe(5)
29+
})
30+
})

0 commit comments

Comments
 (0)