

























@@ -100,17 +100,31 @@ function setDefaultRouteState() {
100100}));
101101}
102102103+type MockWithCalls = { mock: { calls: unknown[][] } };
104+105+function firstMockCall(mock: MockWithCalls, label: string): unknown[] {
106+const call = mock.mock.calls.at(0);
107+if (!call) {
108+throw new Error(`expected ${label} call`);
109+}
110+return call;
111+}
112+113+function firstMockArg(mock: MockWithCalls, label: string) {
114+return firstMockCall(mock, label)[0];
115+}
116+103117function firstStatusCall(): {
104118cfg: OpenClawConfig;
105119sessionKey: string;
106120channel: string;
107121isGroup: boolean;
108122defaultGroupActivation: () => "always" | "mention";
109123} {
110-const call = runtimeModuleMocks.resolveDirectStatusReplyForSession.mock.calls[0]?.[0];
111-if (!call) {
112-throw new Error("expected resolveDirectStatusReplyForSession to be called");
113-}
124+const call = firstMockArg(
125+ runtimeModuleMocks.resolveDirectStatusReplyForSession,
126+"resolveDirectStatusReplyForSession",
127+);
114128return call as {
115129cfg: OpenClawConfig;
116130sessionKey: string;
@@ -162,7 +176,7 @@ describe("discord native /status", () => {
162176expect(runtimeModuleMocks.resolveDirectStatusReplyForSession).toHaveBeenCalledTimes(1);
163177expect(runtimeModuleMocks.dispatchReplyWithDispatcher).not.toHaveBeenCalled();
164178expect(interaction.followUp).toHaveBeenCalledTimes(1);
165-expect(interaction.followUp.mock.calls[0]?.[0]).toStrictEqual({
179+expect(firstMockArg(interaction.followUp, "interaction.followUp")).toStrictEqual({
166180content: "status reply",
167181ephemeral: true,
168182});
@@ -193,7 +207,7 @@ describe("discord native /status", () => {
193207expect(runtimeModuleMocks.resolveDirectStatusReplyForSession).toHaveBeenCalledTimes(1);
194208expect(executePluginCommand).not.toHaveBeenCalled();
195209expect(interaction.followUp).toHaveBeenCalledTimes(1);
196-expect(interaction.followUp.mock.calls[0]?.[0]).toStrictEqual({
210+expect(firstMockArg(interaction.followUp, "interaction.followUp")).toStrictEqual({
197211content: "status reply",
198212ephemeral: true,
199213});
@@ -227,13 +241,13 @@ describe("discord native /status", () => {
227241await (command as { run: (interaction: unknown) => Promise<void> }).run(interaction as unknown);
228242229243expect(runtimeModuleMocks.loadWebMedia).toHaveBeenCalledTimes(1);
230-const [mediaUrl, mediaOptions] = runtimeModuleMocks.loadWebMedia.mock.calls[0] ?? [];
244+const [mediaUrl, mediaOptions] = firstMockCall(runtimeModuleMocks.loadWebMedia, "loadWebMedia");
231245expect(mediaUrl).toBe("https://example.com/status.png");
232246expect(Array.isArray((mediaOptions as { localRoots?: unknown } | undefined)?.localRoots)).toBe(
233247true,
234248);
235249expect(interaction.followUp.mock.calls.length).toBeGreaterThan(1);
236-const firstPayload = interaction.followUp.mock.calls[0]?.[0] as
250+const firstPayload = firstMockArg(interaction.followUp, "interaction.followUp") as
237251| { ephemeral?: boolean; files?: Array<{ name?: string; data?: unknown }> }
238252| undefined;
239253expect(firstPayload?.ephemeral).toBe(true);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。