From a786d8dfcb2669ad9acd288d09a1efd77ce7c2c3 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 05:20:50 +0100 Subject: [PATCH] test: guard inbound claim logger mock calls --- src/plugins/wired-hooks-inbound-claim.test.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/plugins/wired-hooks-inbound-claim.test.ts b/src/plugins/wired-hooks-inbound-claim.test.ts index f67caacba6d..eeb0664600d 100644 --- a/src/plugins/wired-hooks-inbound-claim.test.ts +++ b/src/plugins/wired-hooks-inbound-claim.test.ts @@ -33,6 +33,18 @@ function createInboundClaimForumCtx() { }; } +function expectFirstErrorLog( + logger: { error: ReturnType }, + expected: readonly unknown[], +): void { + expect(logger.error).toHaveBeenCalledTimes(1); + const call = logger.error.mock.calls.at(0); + if (!call) { + throw new Error("expected logger.error call"); + } + expect(call).toEqual(expected); +} + describe("inbound_claim hook runner", () => { it("stops at the first handler that claims the event", async () => { const first = vi.fn().mockResolvedValue({ handled: true }); @@ -81,10 +93,7 @@ describe("inbound_claim hook runner", () => { ); expect(result).toEqual({ handled: true }); - expect(logger.error).toHaveBeenCalledTimes(1); - expect(logger.error.mock.calls[0]).toEqual([ - "[hooks] inbound_claim handler from test-plugin failed: boom", - ]); + expectFirstErrorLog(logger, ["[hooks] inbound_claim handler from test-plugin failed: boom"]); expect(succeeding).toHaveBeenCalledTimes(1); }); @@ -194,8 +203,7 @@ describe("inbound_claim hook runner", () => { await vi.advanceTimersByTimeAsync(5); await expect(run).resolves.toEqual({ status: "error", error: "timed out after 5ms" }); - expect(logger.error).toHaveBeenCalledTimes(1); - expect(logger.error.mock.calls[0]).toEqual([ + expectFirstErrorLog(logger, [ "[hooks] inbound_claim handler from test-plugin failed: timed out after 5ms", ]); } finally {