

























@@ -22,8 +22,16 @@ vi.mock("../send.js", () => ({
2222import { setMatrixRuntime } from "../../runtime.js";
2323import { deliverMatrixReplies } from "./replies.js";
242425+function sendCall(index: number) {
26+const call = sendMessageMatrixMock.mock.calls.at(index);
27+if (!call) {
28+throw new Error(`Expected send call at index ${index}`);
29+}
30+return call;
31+}
32+2533function sendOptions(index: number): Record<string, unknown> {
26-const options = sendMessageMatrixMock.mock.calls[index]?.[2];
34+const options = sendCall(index)[2];
2735if (!options || typeof options !== "object") {
2836throw new Error(`Expected send options at call ${index}`);
2937}
@@ -127,13 +135,13 @@ describe("deliverMatrixReplies", () => {
127135});
128136129137expect(sendMessageMatrixMock).toHaveBeenCalledTimes(3);
130-expect(sendMessageMatrixMock.mock.calls[0]?.[0]).toBe("room:2");
131-expect(sendMessageMatrixMock.mock.calls[0]?.[1]).toBe("caption");
138+expect(sendCall(0)[0]).toBe("room:2");
139+expect(sendCall(0)[1]).toBe("caption");
132140expect(sendOptions(0).mediaUrl).toBe("https://example.com/a.jpg");
133141expect(sendOptions(0).mediaLocalRoots).toEqual(["/tmp/openclaw-matrix-test"]);
134142expect(sendOptions(0).replyToId).toBe("reply-media");
135-expect(sendMessageMatrixMock.mock.calls[1]?.[0]).toBe("room:2");
136-expect(sendMessageMatrixMock.mock.calls[1]?.[1]).toBe("");
143+expect(sendCall(1)[0]).toBe("room:2");
144+expect(sendCall(1)[1]).toBe("");
137145expect(sendOptions(1).mediaUrl).toBe("https://example.com/b.jpg");
138146expect(sendOptions(1).mediaLocalRoots).toEqual(["/tmp/openclaw-matrix-test"]);
139147expect(sendOptions(1).replyToId).toBe("reply-media");
@@ -183,8 +191,8 @@ describe("deliverMatrixReplies", () => {
183191});
184192185193expect(sendMessageMatrixMock).toHaveBeenCalledTimes(1);
186-expect(sendMessageMatrixMock.mock.calls[0]?.[0]).toBe("room:5");
187-expect(sendMessageMatrixMock.mock.calls[0]?.[1]).toBe("Visible answer");
194+expect(sendCall(0)[0]).toBe("room:5");
195+expect(sendCall(0)[1]).toBe("Visible answer");
188196expect(sendOptions(0).cfg).toBe(cfg);
189197});
190198@@ -221,8 +229,8 @@ describe("deliverMatrixReplies", () => {
221229accountId: "ops",
222230tableMode: "code",
223231});
224-expect(sendMessageMatrixMock.mock.calls[0]?.[0]).toBe("room:4");
225-expect(sendMessageMatrixMock.mock.calls[0]?.[1]).toBe("hello");
232+expect(sendCall(0)[0]).toBe("room:4");
233+expect(sendCall(0)[1]).toBe("hello");
226234expect(sendOptions(0).cfg).toBe(explicitCfg);
227235expect(sendOptions(0).accountId).toBe("ops");
228236expect(sendOptions(0).replyToId).toBe("reply-1");
@@ -241,8 +249,8 @@ describe("deliverMatrixReplies", () => {
241249replyToMode: "off",
242250});
243251244-expect(sendMessageMatrixMock.mock.calls[0]?.[0]).toBe("room:6");
245-expect(sendMessageMatrixMock.mock.calls[0]?.[1]).toBe("caption");
252+expect(sendCall(0)[0]).toBe("room:6");
253+expect(sendCall(0)[1]).toBe("caption");
246254expect(sendOptions(0).mediaUrl).toBe("https://example.com/a.jpg");
247255});
248256});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。