@@ -16,6 +16,7 @@ describe('SyntheticMouseEvent', () => {
1616 let container ;
1717
1818 beforeEach ( ( ) => {
19+ jest . resetModules ( ) ;
1920 React = require ( 'react' ) ;
2021 ReactDOM = require ( 'react-dom' ) ;
2122
@@ -77,4 +78,67 @@ describe('SyntheticMouseEvent', () => {
7778 expect ( events [ 1 ] ) . toBe ( 6 ) ;
7879 expect ( events [ 2 ] ) . toBe ( 0 ) ; // mousedown event should have movementX at 0
7980 } ) ;
81+
82+ it ( 'should correctly calculate movementX/Y for capture phase' , ( ) => {
83+ const events = [ ] ;
84+ const onMouseMove = event => {
85+ events . push ( [ 'move' , false , event . movementX , event . movementY ] ) ;
86+ } ;
87+ const onMouseMoveCapture = event => {
88+ events . push ( [ 'move' , true , event . movementX , event . movementY ] ) ;
89+ } ;
90+ const onMouseDown = event => {
91+ events . push ( [ 'down' , false , event . movementX , event . movementY ] ) ;
92+ } ;
93+ const onMouseDownCapture = event => {
94+ events . push ( [ 'down' , true , event . movementX , event . movementY ] ) ;
95+ } ;
96+
97+ const node = ReactDOM . render (
98+ < div
99+ onMouseMove = { onMouseMove }
100+ onMouseMoveCapture = { onMouseMoveCapture }
101+ onMouseDown = { onMouseDown }
102+ onMouseDownCapture = { onMouseDownCapture }
103+ /> ,
104+ container ,
105+ ) ;
106+
107+ let event = new MouseEvent ( 'mousemove' , {
108+ relatedTarget : null ,
109+ bubbles : true ,
110+ screenX : 2 ,
111+ screenY : 2 ,
112+ } ) ;
113+
114+ node . dispatchEvent ( event ) ;
115+
116+ event = new MouseEvent ( 'mousemove' , {
117+ relatedTarget : null ,
118+ bubbles : true ,
119+ screenX : 8 ,
120+ screenY : 9 ,
121+ } ) ;
122+
123+ node . dispatchEvent ( event ) ;
124+
125+ // Now trigger a mousedown event to see if movementX has changed back to 0
126+ event = new MouseEvent ( 'mousedown' , {
127+ relatedTarget : null ,
128+ bubbles : true ,
129+ screenX : 25 ,
130+ screenY : 65 ,
131+ } ) ;
132+
133+ node . dispatchEvent ( event ) ;
134+
135+ expect ( events ) . toEqual ( [
136+ [ 'move' , true , 0 , 0 ] ,
137+ [ 'move' , false , 0 , 0 ] ,
138+ [ 'move' , true , 6 , 7 ] ,
139+ [ 'move' , false , 6 , 7 ] ,
140+ [ 'down' , true , 0 , 0 ] ,
141+ [ 'down' , false , 0 , 0 ] ,
142+ ] ) ;
143+ } ) ;
80144} ) ;
0 commit comments