@@ -87,6 +87,29 @@ describe('onLongPress', () => {
8787 expect ( onParentLongPressCallback ) . toHaveBeenCalledTimes ( 0 )
8888 }
8989
90+ async function stopEventListeners ( isRef : boolean ) {
91+ const onLongPressCallback = vi . fn ( )
92+ const stop = onLongPress ( isRef ? element : element . value , onLongPressCallback , { modifiers : { stop : true } } )
93+
94+ // before calling stop, the callback should be called
95+ element . value . dispatchEvent ( pointerdownEvent )
96+
97+ await promiseTimeout ( 500 )
98+
99+ expect ( onLongPressCallback ) . toHaveBeenCalledTimes ( 1 )
100+
101+ stop ( )
102+
103+ // before calling stop, the callback should no longer be called
104+ onLongPressCallback . mockClear ( )
105+
106+ element . value . dispatchEvent ( pointerdownEvent )
107+
108+ await promiseTimeout ( 500 )
109+
110+ expect ( onLongPressCallback ) . toHaveBeenCalledTimes ( 0 )
111+ }
112+
90113 function suites ( isRef : boolean ) {
91114 describe ( 'given no options' , ( ) => {
92115 it ( 'should trigger longpress after 500ms' , ( ) => triggerCallback ( isRef ) )
@@ -97,6 +120,7 @@ describe('onLongPress', () => {
97120 it ( 'should not tirgger longpress when child element on longpress' , ( ) => notTriggerCallbackOnChildLongPress ( isRef ) )
98121 it ( 'should work with once and prevent modifiers' , ( ) => workOnceAndPreventModifiers ( isRef ) )
99122 it ( 'should stop propagation' , ( ) => stopPropagation ( isRef ) )
123+ it ( 'should remove event listeners after being stopped' , ( ) => stopEventListeners ( isRef ) )
100124 } )
101125 }
102126
0 commit comments