@@ -420,8 +420,10 @@ describe('usePress', function () {
420420
421421 let el = res . getByText ( 'test' ) ;
422422 el . releasePointerCapture = jest . fn ( ) ;
423+ el . hasPointerCapture = jest . fn ( ) . mockReturnValue ( true ) ;
423424 fireEvent ( el , pointerEvent ( 'pointerdown' , { pointerId : 1 , pointerType : 'mouse' , clientX : 0 , clientY : 0 } ) ) ;
424- expect ( el . releasePointerCapture ) . toHaveBeenCalled ( ) ;
425+ expect ( el . hasPointerCapture ) . toHaveBeenCalledWith ( 1 ) ;
426+ expect ( el . releasePointerCapture ) . toHaveBeenCalledWith ( 1 ) ;
425427 // react listens for pointerout and pointerover instead of pointerleave and pointerenter...
426428 fireEvent ( el , pointerEvent ( 'pointerout' , { pointerId : 1 , pointerType : 'mouse' , clientX : 100 , clientY : 100 } ) ) ;
427429 fireEvent ( document , pointerEvent ( 'pointerup' , { pointerId : 1 , pointerType : 'mouse' , clientX : 100 , clientY : 100 } ) ) ;
@@ -560,6 +562,16 @@ describe('usePress', function () {
560562 ] ) ;
561563 } ) ;
562564
565+ it ( 'should not call releasePointerCapture when hasPointerCapture returns false' , function ( ) {
566+ let res = render ( < Example /> ) ;
567+ let el = res . getByText ( 'test' ) ;
568+ el . releasePointerCapture = jest . fn ( ) ;
569+ el . hasPointerCapture = jest . fn ( ) . mockReturnValue ( false ) ;
570+ fireEvent ( el , pointerEvent ( 'pointerdown' , { pointerId : 1 , pointerType : 'mouse' , clientX : 0 , clientY : 0 } ) ) ;
571+ expect ( el . hasPointerCapture ) . toHaveBeenCalledWith ( 1 ) ;
572+ expect ( el . releasePointerCapture ) . not . toHaveBeenCalled ( ) ;
573+ } ) ;
574+
563575 it ( 'should handle pointer cancel events' , function ( ) {
564576 let events = [ ] ;
565577 let addEvent = ( e ) => events . push ( e ) ;
@@ -4011,8 +4023,10 @@ describe('usePress', function () {
40114023
40124024 const el = shadowRoot . getElementById ( 'testElement' ) ;
40134025 el . releasePointerCapture = jest . fn ( ) ;
4026+ el . hasPointerCapture = jest . fn ( ) . mockReturnValue ( true ) ;
40144027 fireEvent ( el , pointerEvent ( 'pointerdown' , { pointerId : 1 , pointerType : 'mouse' , clientX : 0 , clientY : 0 } ) ) ;
4015- expect ( el . releasePointerCapture ) . toHaveBeenCalled ( ) ;
4028+ expect ( el . hasPointerCapture ) . toHaveBeenCalledWith ( 1 ) ;
4029+ expect ( el . releasePointerCapture ) . toHaveBeenCalledWith ( 1 ) ;
40164030 // react listens for pointerout and pointerover instead of pointerleave and pointerenter...
40174031 fireEvent ( el , pointerEvent ( 'pointerout' , { pointerId : 1 , pointerType : 'mouse' , clientX : 100 , clientY : 100 } ) ) ;
40184032 fireEvent ( document , pointerEvent ( 'pointerup' , { pointerId : 1 , pointerType : 'mouse' , clientX : 100 , clientY : 100 } ) ) ;
0 commit comments