diff --git a/src/cli/skills-cli.commands.test.ts b/src/cli/skills-cli.commands.test.ts index e8822d59dd65..50dad8124d57 100644 --- a/src/cli/skills-cli.commands.test.ts +++ b/src/cli/skills-cli.commands.test.ts @@ -8,6 +8,11 @@ import { type AgentSelectionContext, } from "../agents/agent-scope-config.js"; import { GatewayTransportError } from "../gateway/transport-error.js"; +import { + expectObjectFields, + mockCall, + mockFirstObjectArg, +} from "../test-utils/mock-call-assertions.js"; import { registerSkillsCli } from "./skills-cli.js"; const ORIGINAL_STDIN_TTY = Object.getOwnPropertyDescriptor(process.stdin, "isTTY"); @@ -188,33 +193,6 @@ afterEach(() => { vi.unstubAllEnvs(); }); -function mockCall(mock: unknown, index = 0): Array { - const calls = (mock as { mock?: { calls?: Array> } }).mock?.calls ?? []; - const call = calls.at(index); - if (!call) { - throw new Error(`Expected mock call ${index + 1}`); - } - return call; -} - -function mockFirstObjectArg(mock: unknown): Record { - const [arg] = mockCall(mock); - if (!arg || typeof arg !== "object") { - throw new Error("expected first mock argument object"); - } - return arg as Record; -} - -function expectObjectFields(value: unknown, expected: Record): void { - if (!value || typeof value !== "object") { - throw new Error("expected object fields"); - } - const record = value as Record; - for (const [key, expectedValue] of Object.entries(expected)) { - expect(record[key], key).toEqual(expectedValue); - } -} - function expectLogger(value: unknown): void { if (!value || typeof value !== "object") { throw new Error("expected logger object");