File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
packages/hooks/src/useLockFn/__tests__ Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
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
+ } )
You can’t perform that action at this time.
0 commit comments