diff --git a/.changeset/famous-kiwis-itch.md b/.changeset/famous-kiwis-itch.md new file mode 100644 index 000000000..42bc2efd0 --- /dev/null +++ b/.changeset/famous-kiwis-itch.md @@ -0,0 +1,5 @@ +--- +"@inngest/test": patch +--- + +Fix `@inngest/test` automatic spying not accounting for `step.**` diff --git a/packages/test/src/spy.ts b/packages/test/src/spy.ts index dd4dc0a2d..3b5cec8a5 100644 --- a/packages/test/src/spy.ts +++ b/packages/test/src/spy.ts @@ -623,3 +623,18 @@ export function fn( return enhancedSpy as any; } + +export const mockAny = (obj: T): T => { + if (typeof obj === "function") { + return fn(obj as (...args: any[]) => any) as T; + } + + if (typeof obj === "object" && obj !== null) { + return Object.keys(obj).reduce((acc, key) => { + (acc as any)[key] = mockAny(obj[key as keyof typeof obj]); + return acc; + }, obj); + } + + return obj; +}; diff --git a/packages/test/src/util.ts b/packages/test/src/util.ts index 973acb20c..4d3a37455 100644 --- a/packages/test/src/util.ts +++ b/packages/test/src/util.ts @@ -1,7 +1,7 @@ import { internalEvents } from "inngest"; import type { Context, EventPayload } from "inngest/types"; import { ulid } from "ulid"; -import { fn as mockFn } from "./spy.js"; +import { mockAny } from "./spy.js"; /** * The default context transformation function that mocks all step tools. Use @@ -9,22 +9,9 @@ import { fn as mockFn } from "./spy.js"; * this functionality. */ export const mockCtx = (ctx: Readonly): Context.Any => { - const step = Object.keys(ctx.step).reduce( - (acc, key) => { - const tool = ctx.step[key as keyof typeof ctx.step]; - const mock = mockFn(tool); - - return { - ...acc, - [key]: mock, - }; - }, - {} as Context.Any["step"] - ); - return { ...ctx, - step, + step: mockAny(ctx.step), }; };