@@ -2,6 +2,7 @@ import {describe, expect, it} from 'bun:test';
22import {
33 installMiddleClickNavigationGuard ,
44 installMiddleClickNavigationGuardForPlatform ,
5+ type MiddleClickNavigationGuardTarget ,
56 shouldInstallMiddleClickNavigationGuard
67} from '../src/util/middleClickNavigation' ;
78
@@ -11,6 +12,17 @@ function mouseEvent(type: string, button: number) {
1112 return event ;
1213}
1314
15+ function guardTarget ( target : EventTarget ) : MiddleClickNavigationGuardTarget {
16+ return {
17+ addEventListener ( type , listener , options ) {
18+ target . addEventListener ( type , listener as EventListener , options ) ;
19+ } ,
20+ removeEventListener ( type , listener ) {
21+ target . removeEventListener ( type , listener as EventListener ) ;
22+ }
23+ } ;
24+ }
25+
1426describe ( 'middle-click navigation guard' , ( ) => {
1527 it ( 'is enabled only for the Windows desktop app' , ( ) => {
1628 expect (
@@ -26,7 +38,7 @@ describe('middle-click navigation guard', () => {
2638
2739 it ( 'prevents middle-button auxiliary clicks' , ( ) => {
2840 const target = new EventTarget ( ) ;
29- installMiddleClickNavigationGuard ( target ) ;
41+ installMiddleClickNavigationGuard ( guardTarget ( target ) ) ;
3042 const event = mouseEvent ( 'auxclick' , 1 ) ;
3143
3244 target . dispatchEvent ( event ) ;
@@ -36,7 +48,7 @@ describe('middle-click navigation guard', () => {
3648
3749 it . each ( [ 0 , 2 ] ) ( 'does not prevent mouse button %i' , ( button ) => {
3850 const target = new EventTarget ( ) ;
39- installMiddleClickNavigationGuard ( target ) ;
51+ installMiddleClickNavigationGuard ( guardTarget ( target ) ) ;
4052 const event = mouseEvent ( 'auxclick' , button ) ;
4153
4254 target . dispatchEvent ( event ) ;
@@ -46,7 +58,7 @@ describe('middle-click navigation guard', () => {
4658
4759 it ( 'does not prevent the middle-button press that starts autoscroll' , ( ) => {
4860 const target = new EventTarget ( ) ;
49- installMiddleClickNavigationGuard ( target ) ;
61+ installMiddleClickNavigationGuard ( guardTarget ( target ) ) ;
5062 const event = mouseEvent ( 'mousedown' , 1 ) ;
5163
5264 target . dispatchEvent ( event ) ;
@@ -56,7 +68,7 @@ describe('middle-click navigation guard', () => {
5668
5769 it ( 'removes the guard during cleanup' , ( ) => {
5870 const target = new EventTarget ( ) ;
59- const cleanup = installMiddleClickNavigationGuard ( target ) ;
71+ const cleanup = installMiddleClickNavigationGuard ( guardTarget ( target ) ) ;
6072 cleanup ( ) ;
6173 const event = mouseEvent ( 'auxclick' , 1 ) ;
6274
@@ -74,7 +86,7 @@ describe('middle-click navigation guard', () => {
7486 const eventTarget = new EventTarget ( ) ;
7587 const cleanup = installMiddleClickNavigationGuardForPlatform ( 'tauri' , {
7688 userAgent : 'Windows NT 10.0' ,
77- eventTarget
89+ eventTarget : guardTarget ( eventTarget )
7890 } ) ;
7991 const guardedEvent = mouseEvent ( 'auxclick' , 1 ) ;
8092
0 commit comments