@@ -249,6 +249,58 @@ describe('SyntheticEvent', () => {
249249 expect ( expectedCount ) . toBe ( 1 ) ;
250250 } ) ;
251251
252+ it ( 'should warn when calling `isPropagationStopped` if the synthetic event has not been persisted' , ( ) => {
253+ let node ;
254+ let expectedCount = 0 ;
255+ let syntheticEvent ;
256+
257+ const eventHandler = e => {
258+ syntheticEvent = e ;
259+ expectedCount ++ ;
260+ } ;
261+ node = ReactDOM . render ( < div onClick = { eventHandler } /> , container ) ;
262+
263+ const event = document . createEvent ( 'Event' ) ;
264+ event . initEvent ( 'click' , true , true ) ;
265+ node . dispatchEvent ( event ) ;
266+
267+ expect ( ( ) => expect ( syntheticEvent . isPropagationStopped ( ) ) . toBe ( false ) ) . toWarnDev (
268+ 'Warning: This synthetic event is reused for performance reasons. If ' +
269+ "you're seeing this, you're accessing the method `isPropagationStopped` on a " +
270+ 'released/nullified synthetic event. This is a no-op function. If you must ' +
271+ 'keep the original synthetic event around, use event.persist(). ' +
272+ 'See https://fb.me/react-event-pooling for more information.' ,
273+ { withoutStack : true } ,
274+ ) ;
275+ expect ( expectedCount ) . toBe ( 1 ) ;
276+ } ) ;
277+
278+ it ( 'should warn when calling `isDefaultPrevented` if the synthetic event has not been persisted' , ( ) => {
279+ let node ;
280+ let expectedCount = 0 ;
281+ let syntheticEvent ;
282+
283+ const eventHandler = e => {
284+ syntheticEvent = e ;
285+ expectedCount ++ ;
286+ } ;
287+ node = ReactDOM . render ( < div onClick = { eventHandler } /> , container ) ;
288+
289+ const event = document . createEvent ( 'Event' ) ;
290+ event . initEvent ( 'click' , true , true ) ;
291+ node . dispatchEvent ( event ) ;
292+
293+ expect ( ( ) => expect ( syntheticEvent . isDefaultPrevented ( ) ) . toBe ( false ) ) . toWarnDev (
294+ 'Warning: This synthetic event is reused for performance reasons. If ' +
295+ "you're seeing this, you're accessing the method `isDefaultPrevented` on a " +
296+ 'released/nullified synthetic event. This is a no-op function. If you must ' +
297+ 'keep the original synthetic event around, use event.persist(). ' +
298+ 'See https://fb.me/react-event-pooling for more information.' ,
299+ { withoutStack : true } ,
300+ ) ;
301+ expect ( expectedCount ) . toBe ( 1 ) ;
302+ } ) ;
303+
252304 it ( 'should properly log warnings when events simulated with rendered components' , ( ) => {
253305 let event ;
254306 function assignEvent ( e ) {
0 commit comments