@@ -50,6 +50,14 @@ function expectWarnContaining(fragment: string) {
5050 expect ( warnMessages ( ) . some ( ( message ) => message . includes ( fragment ) ) ) . toBe ( true ) ;
5151}
5252
53+ function mockCall ( mock : ReturnType < typeof vi . fn > , index = 0 ) : unknown [ ] {
54+ const call = mock . mock . calls . at ( index ) ;
55+ if ( ! call ) {
56+ throw new Error ( `Expected mock call ${ index } ` ) ;
57+ }
58+ return call ;
59+ }
60+
5361function enableAdvertiserUnitMode ( hostname = "test-host" ) {
5462 // Allow advertiser to run in unit tests.
5563 delete process . env . VITEST ;
@@ -311,7 +319,7 @@ describe("gateway bonjour advertiser", () => {
311319 const started = await startAdvertiser ( { gatewayPort : 18789 } ) ;
312320 childProcessModule . exec ( 'arp -a | findstr /C:"---"' , ( ) => { } ) ;
313321
314- const execCall = execMock . mock . calls [ 0 ] ;
322+ const execCall = mockCall ( execMock ) ;
315323 expect ( execCall ?. [ 0 ] ) . toBe ( 'arp -a | findstr /C:"---"' ) ;
316324 expect ( execCall ?. [ 1 ] ) . toEqual ( { windowsHide : true } ) ;
317325 expect ( execCall ?. [ 2 ] ) . toBeTypeOf ( "function" ) ;
@@ -422,10 +430,10 @@ describe("gateway bonjour advertiser", () => {
422430 sshPort : 2222 ,
423431 } ) ;
424432
425- const handler = registerUnhandledRejectionHandler . mock . calls [ 0 ] ?. [ 0 ] as
433+ const handler = mockCall ( registerUnhandledRejectionHandler ) . at ( 0 ) as
426434 | ( ( reason : unknown ) => boolean )
427435 | undefined ;
428- const exceptionHandler = registerUncaughtExceptionHandler . mock . calls [ 0 ] ?. [ 0 ] as
436+ const exceptionHandler = mockCall ( registerUncaughtExceptionHandler ) . at ( 0 ) as
429437 | ( ( reason : unknown ) => boolean )
430438 | undefined ;
431439 expect ( handler ) . toBeTypeOf ( "function" ) ;
@@ -478,7 +486,7 @@ describe("gateway bonjour advertiser", () => {
478486 sshPort : 2222 ,
479487 } ) ;
480488
481- const handler = registerUnhandledRejectionHandler . mock . calls [ 0 ] ?. [ 0 ] as
489+ const handler = mockCall ( registerUnhandledRejectionHandler ) . at ( 0 ) as
482490 | ( ( reason : unknown ) => boolean )
483491 | undefined ;
484492 expect ( handler ?.( new Error ( "CIAO ANNOUNCEMENT CANCELLED" ) ) ) . toBe ( true ) ;
0 commit comments