diff --git a/src/commands/gateway-install-token.test.ts b/src/commands/gateway-install-token.test.ts index 2c2750c1632..55a84dc81c8 100644 --- a/src/commands/gateway-install-token.test.ts +++ b/src/commands/gateway-install-token.test.ts @@ -59,6 +59,14 @@ vi.mock("./random-token.js", () => ({ randomToken: randomTokenMock, })); +function firstReplaceConfigRequest(): unknown { + const [call] = replaceConfigFileMock.mock.calls; + if (!call) { + throw new Error("expected config replace call"); + } + return call[0]; +} + describe("resolveGatewayInstallToken", () => { beforeEach(() => { vi.clearAllMocks(); @@ -193,7 +201,7 @@ describe("resolveGatewayInstallToken", () => { expect(result.warnings.join("\n")).toContain("saving to config"); expect(replaceConfigFileMock).toHaveBeenCalledOnce(); - expect(replaceConfigFileMock.mock.calls[0]?.[0]).toStrictEqual({ + expect(firstReplaceConfigRequest()).toStrictEqual({ nextConfig: { gateway: { auth: { diff --git a/src/commands/tasks-json.test.ts b/src/commands/tasks-json.test.ts index ff023e0c41d..9f7aff500c7 100644 --- a/src/commands/tasks-json.test.ts +++ b/src/commands/tasks-json.test.ts @@ -21,7 +21,11 @@ function createRuntime(): RuntimeEnv { } function readJsonLog(runtime: RuntimeEnv): unknown { - return JSON.parse(String(vi.mocked(runtime.log).mock.calls[0]?.[0])); + const [call] = vi.mocked(runtime.log).mock.calls; + if (!call) { + throw new Error("expected runtime log call"); + } + return JSON.parse(String(call[0])); } async function withTaskJsonStateDir(run: () => Promise): Promise { diff --git a/src/daemon/systemd.test.ts b/src/daemon/systemd.test.ts index 1f01a7c4406..aa208f28a83 100644 --- a/src/daemon/systemd.test.ts +++ b/src/daemon/systemd.test.ts @@ -62,7 +62,11 @@ const createWritableStreamMock = () => { }; function requireFirstWrite(write: ReturnType): string { - const value = write.mock.calls[0]?.[0]; + const [call] = write.mock.calls; + if (!call) { + throw new Error("expected systemd status write"); + } + const [value] = call; if (value === undefined) { throw new Error("expected systemd status write"); } diff --git a/src/hooks/fire-and-forget.test.ts b/src/hooks/fire-and-forget.test.ts index a061f0a906a..205d464d5f8 100644 --- a/src/hooks/fire-and-forget.test.ts +++ b/src/hooks/fire-and-forget.test.ts @@ -2,7 +2,11 @@ import { describe, expect, it, vi } from "vitest"; import { fireAndForgetBoundedHook, fireAndForgetHook } from "./fire-and-forget.js"; function requireFirstLog(logger: ReturnType): string { - const message = logger.mock.calls[0]?.[0]; + const [call] = logger.mock.calls; + if (!call) { + throw new Error("expected log call"); + } + const [message] = call; if (typeof message !== "string") { throw new Error("expected string log message"); }