From 6ebc6cad1760fa3ca22dcb880bcba1c55c8cb49e Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 02:50:29 +0100 Subject: [PATCH] test: guard discord webhook fetch mock call --- extensions/discord/src/send.webhook-activity.test.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/extensions/discord/src/send.webhook-activity.test.ts b/extensions/discord/src/send.webhook-activity.test.ts index fc03bd5502d..20c49690d83 100644 --- a/extensions/discord/src/send.webhook-activity.test.ts +++ b/extensions/discord/src/send.webhook-activity.test.ts @@ -26,6 +26,16 @@ vi.mock("openclaw/plugin-sdk/channel-activity-runtime", async () => { let sendWebhookMessageDiscord: typeof import("./send.webhook.js").sendWebhookMessageDiscord; +type MockWithCalls = { mock: { calls: unknown[][] } }; + +function firstMockCall(mock: MockWithCalls, label: string): unknown[] { + const call = mock.mock.calls.at(0); + if (!call) { + throw new Error(`expected ${label} call`); + } + return call; +} + describe("sendWebhookMessageDiscord activity", () => { beforeAll(async () => { ({ sendWebhookMessageDiscord } = await import("./send.webhook.js")); @@ -126,7 +136,7 @@ describe("sendWebhookMessageDiscord activity", () => { const fetchMock = vi.mocked(fetch); expect(fetchMock).toHaveBeenCalledTimes(1); - expect(fetchMock.mock.calls[0]).toEqual([ + expect(firstMockCall(fetchMock, "fetch")).toEqual([ "https://discord.com/api/v10/webhooks/wh-1/tok-1?wait=true&thread_id=thread-1", { method: "POST",