@@ -7,7 +7,7 @@ describe(`events`, () => {
7
7
const el = document . createElement ( 'div' )
8
8
const event = new Event ( 'click' )
9
9
const fn = jest . fn ( )
10
- patchEvent ( el , 'click ' , null , fn , null )
10
+ patchEvent ( el , 'onClick ' , null , fn , null )
11
11
el . dispatchEvent ( event )
12
12
await timeout ( )
13
13
el . dispatchEvent ( event )
@@ -22,9 +22,9 @@ describe(`events`, () => {
22
22
const event = new Event ( 'click' )
23
23
const prevFn = jest . fn ( )
24
24
const nextFn = jest . fn ( )
25
- patchEvent ( el , 'click ' , null , prevFn , null )
25
+ patchEvent ( el , 'onClick ' , null , prevFn , null )
26
26
el . dispatchEvent ( event )
27
- patchEvent ( el , 'click ' , prevFn , nextFn , null )
27
+ patchEvent ( el , 'onClick ' , prevFn , nextFn , null )
28
28
await timeout ( )
29
29
el . dispatchEvent ( event )
30
30
await timeout ( )
@@ -39,7 +39,7 @@ describe(`events`, () => {
39
39
const event = new Event ( 'click' )
40
40
const fn1 = jest . fn ( )
41
41
const fn2 = jest . fn ( )
42
- patchEvent ( el , 'click ' , null , [ fn1 , fn2 ] , null )
42
+ patchEvent ( el , 'onClick ' , null , [ fn1 , fn2 ] , null )
43
43
el . dispatchEvent ( event )
44
44
await timeout ( )
45
45
expect ( fn1 ) . toHaveBeenCalledTimes ( 1 )
@@ -50,8 +50,8 @@ describe(`events`, () => {
50
50
const el = document . createElement ( 'div' )
51
51
const event = new Event ( 'click' )
52
52
const fn = jest . fn ( )
53
- patchEvent ( el , 'click ' , null , fn , null )
54
- patchEvent ( el , 'click ' , fn , null , null )
53
+ patchEvent ( el , 'onClick ' , null , fn , null )
54
+ patchEvent ( el , 'onClick ' , fn , null , null )
55
55
el . dispatchEvent ( event )
56
56
await timeout ( )
57
57
expect ( fn ) . not . toHaveBeenCalled ( )
@@ -67,7 +67,7 @@ describe(`events`, () => {
67
67
once : true
68
68
}
69
69
}
70
- patchEvent ( el , 'click ' , null , nextValue , null )
70
+ patchEvent ( el , 'onClick ' , null , nextValue , null )
71
71
el . dispatchEvent ( event )
72
72
await timeout ( )
73
73
el . dispatchEvent ( event )
@@ -86,8 +86,8 @@ describe(`events`, () => {
86
86
once : true
87
87
}
88
88
}
89
- patchEvent ( el , 'click ' , null , prevFn , null )
90
- patchEvent ( el , 'click ' , prevFn , nextValue , null )
89
+ patchEvent ( el , 'onClick ' , null , prevFn , null )
90
+ patchEvent ( el , 'onClick ' , prevFn , nextValue , null )
91
91
el . dispatchEvent ( event )
92
92
await timeout ( )
93
93
el . dispatchEvent ( event )
@@ -106,12 +106,30 @@ describe(`events`, () => {
106
106
once : true
107
107
}
108
108
}
109
- patchEvent ( el , 'click ' , null , nextValue , null )
110
- patchEvent ( el , 'click ' , nextValue , null , null )
109
+ patchEvent ( el , 'onClick ' , null , nextValue , null )
110
+ patchEvent ( el , 'onClick ' , nextValue , null , null )
111
111
el . dispatchEvent ( event )
112
112
await timeout ( )
113
113
el . dispatchEvent ( event )
114
114
await timeout ( )
115
115
expect ( fn ) . not . toHaveBeenCalled ( )
116
116
} )
117
+
118
+ it ( 'should assign native onclick attribute' , async ( ) => {
119
+ const el = document . createElement ( 'div' )
120
+ const event = new Event ( 'click' )
121
+ const fn = ( ( window as any ) . _nativeClickSpy = jest . fn ( ) )
122
+
123
+ patchEvent ( el , 'onclick' , null , '_nativeClickSpy()' as any )
124
+ el . dispatchEvent ( event )
125
+ await timeout ( )
126
+ expect ( fn ) . toHaveBeenCalledTimes ( 1 )
127
+
128
+ const fn2 = jest . fn ( )
129
+ patchEvent ( el , 'onclick' , null , fn2 )
130
+ el . dispatchEvent ( event )
131
+ await timeout ( )
132
+ expect ( fn ) . toHaveBeenCalledTimes ( 1 )
133
+ expect ( fn2 ) . toHaveBeenCalledTimes ( 1 )
134
+ } )
117
135
} )
0 commit comments