diff --git a/extensions/discord/src/monitor/provider.test.ts b/extensions/discord/src/monitor/provider.test.ts index ca1955e54ff..1df86950193 100644 --- a/extensions/discord/src/monitor/provider.test.ts +++ b/extensions/discord/src/monitor/provider.test.ts @@ -104,6 +104,14 @@ function createConfigWithDiscordAccount(overrides: Record = {}) type MockCallReader = { mock: { calls: unknown[][] } }; +function firstMockArg(mock: MockCallReader, label: string) { + const firstCall = mock.mock.calls.at(0); + if (!firstCall) { + throw new Error(`expected ${label} mock call`); + } + return firstCall[0]; +} + function mockMessages(mock: unknown): string[] { return (mock as MockCallReader).mock.calls.map((call) => { const message = call[0]; @@ -154,7 +162,7 @@ describe("monitorDiscordProvider", () => { | { listenerTimeout?: number; slowListenerThreshold?: number } | undefined => { expect(clientConstructorOptionsMock).toHaveBeenCalledTimes(1); - const opts = clientConstructorOptionsMock.mock.calls[0]?.[0] as { + const opts = firstMockArg(clientConstructorOptionsMock, "Discord client constructor") as { eventQueue?: { listenerTimeout?: number; slowListenerThreshold?: number }; }; return opts.eventQueue; @@ -166,13 +174,11 @@ describe("monitorDiscordProvider", () => { requestOptions?: { timeout?: number; runtimeProfile?: string; maxQueueSize?: number }; } => { expect(clientConstructorOptionsMock).toHaveBeenCalledTimes(1); - return ( - (clientConstructorOptionsMock.mock.calls[0]?.[0] as { - clientId?: string; - eventQueue?: { listenerTimeout?: number; slowListenerThreshold?: number }; - requestOptions?: { timeout?: number; runtimeProfile?: string; maxQueueSize?: number }; - }) ?? {} - ); + return firstMockArg(clientConstructorOptionsMock, "Discord client constructor") as { + clientId?: string; + eventQueue?: { listenerTimeout?: number; slowListenerThreshold?: number }; + requestOptions?: { timeout?: number; runtimeProfile?: string; maxQueueSize?: number }; + }; }; const getHealthProbe = () => { @@ -693,7 +699,7 @@ describe("monitorDiscordProvider", () => { reason: "status-timeout", }); - const firstCall = getAcpSessionStatusMock.mock.calls[0]?.[0] as + const firstCall = firstMockArg(getAcpSessionStatusMock, "ACP session status") as | { signal?: AbortSignal } | undefined; if (!firstCall?.signal) {