@@ -137,6 +137,93 @@ const eventTypes = [
137
137
} ,
138
138
]
139
139
140
+ const bubblingEvents = [
141
+ 'copy' ,
142
+ 'cut' ,
143
+ 'paste' ,
144
+ 'compositionEnd' ,
145
+ 'compositionStart' ,
146
+ 'compositionUpdate' ,
147
+ 'keyDown' ,
148
+ 'keyPress' ,
149
+ 'keyUp' ,
150
+ 'focusIn' ,
151
+ 'focusOut' ,
152
+ 'change' ,
153
+ 'input' ,
154
+ 'submit' ,
155
+ 'reset' ,
156
+ 'click' ,
157
+ 'contextMenu' ,
158
+ 'dblClick' ,
159
+ 'drag' ,
160
+ 'dragEnd' ,
161
+ 'dragEnter' ,
162
+ 'dragExit' ,
163
+ 'dragLeave' ,
164
+ 'dragOver' ,
165
+ 'dragStart' ,
166
+ 'drop' ,
167
+ 'mouseDown' ,
168
+ 'mouseMove' ,
169
+ 'mouseOut' ,
170
+ 'mouseOver' ,
171
+ 'mouseUp' ,
172
+ 'select' ,
173
+ 'touchCancel' ,
174
+ 'touchEnd' ,
175
+ 'touchMove' ,
176
+ 'touchStart' ,
177
+ 'wheel' ,
178
+ 'animationStart' ,
179
+ 'animationEnd' ,
180
+ 'animationIteration' ,
181
+ 'transitionEnd' ,
182
+ 'pointerOver' ,
183
+ 'pointerDown' ,
184
+ 'pointerMove' ,
185
+ 'pointerUp' ,
186
+ 'pointerCancel' ,
187
+ 'pointerOut' ,
188
+ ]
189
+
190
+ const nonBubblingEvents = [
191
+ 'focus' ,
192
+ 'blur' ,
193
+ 'invalid' ,
194
+ 'mouseEnter' ,
195
+ 'mouseLeave' ,
196
+ 'scroll' ,
197
+ 'abort' ,
198
+ 'canPlay' ,
199
+ 'canPlayThrough' ,
200
+ 'durationChange' ,
201
+ 'emptied' ,
202
+ 'encrypted' ,
203
+ 'ended' ,
204
+ 'loadedData' ,
205
+ 'loadedMetadata' ,
206
+ 'loadStart' ,
207
+ 'pause' ,
208
+ 'play' ,
209
+ 'playing' ,
210
+ 'progress' ,
211
+ 'rateChange' ,
212
+ 'seeked' ,
213
+ 'seeking' ,
214
+ 'stalled' ,
215
+ 'suspend' ,
216
+ 'timeUpdate' ,
217
+ 'volumeChange' ,
218
+ 'waiting' ,
219
+ 'load' ,
220
+ 'error' ,
221
+ 'pointerEnter' ,
222
+ 'pointerLeave' ,
223
+ 'gotPointerCapture' ,
224
+ 'lostPointerCapture' ,
225
+ ]
226
+
140
227
eventTypes . forEach ( ( { type, events, elementType} ) => {
141
228
describe ( `${ type } Events` , ( ) => {
142
229
events . forEach ( eventName => {
@@ -151,6 +238,36 @@ eventTypes.forEach(({type, events, elementType}) => {
151
238
} )
152
239
} )
153
240
241
+ describe ( `Bubbling Events` , ( ) => {
242
+ bubblingEvents . forEach ( event =>
243
+ it ( `bubbles ${ event } ` , ( ) => {
244
+ const node = document . createElement ( 'div' )
245
+ const spy = jest . fn ( )
246
+ node . addEventListener ( event . toLowerCase ( ) , spy )
247
+
248
+ const innerNode = document . createElement ( 'div' )
249
+ node . appendChild ( innerNode )
250
+
251
+ fireEvent [ event ] ( innerNode )
252
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 )
253
+ } ) ,
254
+ )
255
+
256
+ nonBubblingEvents . forEach ( event =>
257
+ it ( `doesn't bubble ${ event } ` , ( ) => {
258
+ const node = document . createElement ( 'div' )
259
+ const spy = jest . fn ( )
260
+ node . addEventListener ( event . toLowerCase ( ) , spy )
261
+
262
+ const innerNode = document . createElement ( 'div' )
263
+ node . appendChild ( innerNode )
264
+
265
+ fireEvent [ event ] ( innerNode )
266
+ expect ( spy ) . not . toHaveBeenCalled ( )
267
+ } ) ,
268
+ )
269
+ } )
270
+
154
271
describe ( `Aliased Events` , ( ) => {
155
272
it ( `fires doubleClick` , ( ) => {
156
273
const node = document . createElement ( 'div' )
@@ -215,7 +332,7 @@ test('fires shortcut events on Window', () => {
215
332
window . addEventListener ( 'click' , clickSpy )
216
333
fireEvent . click ( window )
217
334
expect ( clickSpy ) . toHaveBeenCalledTimes ( 1 )
218
- window . removeEventListener ( 'message ' , clickSpy )
335
+ window . removeEventListener ( 'click ' , clickSpy )
219
336
} )
220
337
221
338
test ( 'throws a useful error message when firing events on non-existent nodes' , ( ) => {
0 commit comments