1
1
import { patchEvent } from '../../src/modules/events'
2
- import { nextTick } from '@vue/runtime-dom'
2
+
3
+ const timeout = ( ) => new Promise ( r => setTimeout ( r ) )
3
4
4
5
describe ( `events` , ( ) => {
5
6
it ( 'should assign event handler' , async ( ) => {
@@ -8,11 +9,11 @@ describe(`events`, () => {
8
9
const fn = jest . fn ( )
9
10
patchEvent ( el , 'click' , null , fn , null )
10
11
el . dispatchEvent ( event )
11
- await nextTick ( )
12
+ await timeout ( )
12
13
el . dispatchEvent ( event )
13
- await nextTick ( )
14
+ await timeout ( )
14
15
el . dispatchEvent ( event )
15
- await nextTick ( )
16
+ await timeout ( )
16
17
expect ( fn ) . toHaveBeenCalledTimes ( 3 )
17
18
} )
18
19
@@ -24,11 +25,11 @@ describe(`events`, () => {
24
25
patchEvent ( el , 'click' , null , prevFn , null )
25
26
el . dispatchEvent ( event )
26
27
patchEvent ( el , 'click' , prevFn , nextFn , null )
27
- await nextTick ( )
28
+ await timeout ( )
28
29
el . dispatchEvent ( event )
29
- await nextTick ( )
30
+ await timeout ( )
30
31
el . dispatchEvent ( event )
31
- await nextTick ( )
32
+ await timeout ( )
32
33
expect ( prevFn ) . toHaveBeenCalledTimes ( 1 )
33
34
expect ( nextFn ) . toHaveBeenCalledTimes ( 2 )
34
35
} )
@@ -40,7 +41,7 @@ describe(`events`, () => {
40
41
const fn2 = jest . fn ( )
41
42
patchEvent ( el , 'click' , null , [ fn1 , fn2 ] , null )
42
43
el . dispatchEvent ( event )
43
- await nextTick ( )
44
+ await timeout ( )
44
45
expect ( fn1 ) . toHaveBeenCalledTimes ( 1 )
45
46
expect ( fn2 ) . toHaveBeenCalledTimes ( 1 )
46
47
} )
@@ -52,7 +53,7 @@ describe(`events`, () => {
52
53
patchEvent ( el , 'click' , null , fn , null )
53
54
patchEvent ( el , 'click' , fn , null , null )
54
55
el . dispatchEvent ( event )
55
- await nextTick ( )
56
+ await timeout ( )
56
57
expect ( fn ) . not . toHaveBeenCalled ( )
57
58
} )
58
59
@@ -68,9 +69,9 @@ describe(`events`, () => {
68
69
}
69
70
patchEvent ( el , 'click' , null , nextValue , null )
70
71
el . dispatchEvent ( event )
71
- await nextTick ( )
72
+ await timeout ( )
72
73
el . dispatchEvent ( event )
73
- await nextTick ( )
74
+ await timeout ( )
74
75
expect ( fn ) . toHaveBeenCalledTimes ( 1 )
75
76
} )
76
77
@@ -88,9 +89,9 @@ describe(`events`, () => {
88
89
patchEvent ( el , 'click' , null , prevFn , null )
89
90
patchEvent ( el , 'click' , prevFn , nextValue , null )
90
91
el . dispatchEvent ( event )
91
- await nextTick ( )
92
+ await timeout ( )
92
93
el . dispatchEvent ( event )
93
- await nextTick ( )
94
+ await timeout ( )
94
95
expect ( prevFn ) . not . toHaveBeenCalled ( )
95
96
expect ( nextFn ) . toHaveBeenCalledTimes ( 1 )
96
97
} )
@@ -108,9 +109,9 @@ describe(`events`, () => {
108
109
patchEvent ( el , 'click' , null , nextValue , null )
109
110
patchEvent ( el , 'click' , nextValue , null , null )
110
111
el . dispatchEvent ( event )
111
- await nextTick ( )
112
+ await timeout ( )
112
113
el . dispatchEvent ( event )
113
- await nextTick ( )
114
+ await timeout ( )
114
115
expect ( fn ) . not . toHaveBeenCalled ( )
115
116
} )
116
117
} )
0 commit comments