




























@@ -50,6 +50,14 @@ function expectWarnContaining(fragment: string) {
5050expect(warnMessages().some((message) => message.includes(fragment))).toBe(true);
5151}
525253+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.
5563delete process.env.VITEST;
@@ -311,7 +319,7 @@ describe("gateway bonjour advertiser", () => {
311319const started = await startAdvertiser({ gatewayPort: 18789 });
312320childProcessModule.exec('arp -a | findstr /C:"---"', () => {});
313321314-const execCall = execMock.mock.calls[0];
322+const execCall = mockCall(execMock);
315323expect(execCall?.[0]).toBe('arp -a | findstr /C:"---"');
316324expect(execCall?.[1]).toEqual({ windowsHide: true });
317325expect(execCall?.[2]).toBeTypeOf("function");
@@ -422,10 +430,10 @@ describe("gateway bonjour advertiser", () => {
422430sshPort: 2222,
423431});
424432425-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;
431439expect(handler).toBeTypeOf("function");
@@ -478,7 +486,7 @@ describe("gateway bonjour advertiser", () => {
478486sshPort: 2222,
479487});
480488481-const handler = registerUnhandledRejectionHandler.mock.calls[0]?.[0] as
489+const handler = mockCall(registerUnhandledRejectionHandler).at(0) as
482490| ((reason: unknown) => boolean)
483491| undefined;
484492expect(handler?.(new Error("CIAO ANNOUNCEMENT CANCELLED"))).toBe(true);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。