@@ -2705,5 +2705,78 @@ describe('ReactDOMComponent', () => {
2705
2705
'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==' ;
2706
2706
} ) ;
2707
2707
} ) ;
2708
+
2709
+ it ( 'triggers events local captured events from children without listeners' , ( ) => {
2710
+ const callback = jest . fn ( ) ;
2711
+ const container = document . createElement ( 'div' ) ;
2712
+
2713
+ ReactDOM . render (
2714
+ < div id = "top" onTouchEnd = { callback } >
2715
+ < div id = "middle" >
2716
+ < div id = "bottom" />
2717
+ </ div >
2718
+ </ div > ,
2719
+ container ,
2720
+ ) ;
2721
+
2722
+ const event = document . createEvent ( 'Event' ) ;
2723
+
2724
+ event . initEvent ( 'touchend' , true , true ) ;
2725
+ container . querySelector ( '#bottom' ) . dispatchEvent ( event ) ;
2726
+
2727
+ expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
2728
+ } ) ;
2729
+
2730
+ it ( 'does not double dispatch captured events at the deepest leaf' , ( ) => {
2731
+ const top = jest . fn ( ) ;
2732
+ const middle = jest . fn ( ) ;
2733
+ const bottom = jest . fn ( ) ;
2734
+ const container = document . createElement ( 'div' ) ;
2735
+
2736
+ ReactDOM . render (
2737
+ < div id = "top" onTouchEnd = { top } >
2738
+ < div id = "middle" onTouchEnd = { middle } >
2739
+ < div id = "bottom" onTouchEnd = { bottom } />
2740
+ </ div >
2741
+ </ div > ,
2742
+ container ,
2743
+ ) ;
2744
+
2745
+ const target = container . querySelector ( '#bottom' ) ;
2746
+ const event = document . createEvent ( 'Event' ) ;
2747
+
2748
+ event . initEvent ( 'touchend' , true , true ) ;
2749
+ target . dispatchEvent ( event ) ;
2750
+
2751
+ expect ( top ) . toHaveBeenCalledTimes ( 1 ) ;
2752
+ expect ( middle ) . toHaveBeenCalledTimes ( 1 ) ;
2753
+ expect ( bottom ) . toHaveBeenCalledTimes ( 1 ) ;
2754
+ } ) ;
2755
+
2756
+ it ( 'does not double dispatch captured events at the middle leaf' , ( ) => {
2757
+ const top = jest . fn ( ) ;
2758
+ const middle = jest . fn ( ) ;
2759
+ const bottom = jest . fn ( ) ;
2760
+ const container = document . createElement ( 'div' ) ;
2761
+
2762
+ ReactDOM . render (
2763
+ < div id = "top" onTouchEnd = { top } >
2764
+ < div id = "middle" onTouchEnd = { middle } >
2765
+ < div id = "bottom" onTouchEnd = { bottom } />
2766
+ </ div >
2767
+ </ div > ,
2768
+ container ,
2769
+ ) ;
2770
+
2771
+ const target = container . querySelector ( '#middle' ) ;
2772
+ const event = document . createEvent ( 'Event' ) ;
2773
+
2774
+ event . initEvent ( 'touchend' , true , true ) ;
2775
+ target . dispatchEvent ( event ) ;
2776
+
2777
+ expect ( top ) . toHaveBeenCalledTimes ( 1 ) ;
2778
+ expect ( middle ) . toHaveBeenCalledTimes ( 1 ) ;
2779
+ expect ( bottom ) . toHaveBeenCalledTimes ( 0 ) ;
2780
+ } ) ;
2708
2781
} ) ;
2709
2782
} ) ;
0 commit comments