

























@@ -111,6 +111,18 @@ function makeEchoTracker() {
111111};
112112}
113113114+function mockObjectArg(mockFn: ReturnType<typeof vi.fn>, label: string, callIndex = 0) {
115+const call = mockFn.mock.calls.at(callIndex);
116+if (!call) {
117+throw new Error(`Expected ${label} call ${callIndex}`);
118+}
119+const arg = call.at(0);
120+if (!arg || typeof arg !== "object") {
121+throw new Error(`Expected ${label} call ${callIndex} object argument`);
122+}
123+return arg as Record<string, unknown>;
124+}
125+114126describe("createWebOnMessageHandler audio preflight", () => {
115127beforeEach(() => {
116128events.length = 0;
@@ -164,7 +176,7 @@ describe("createWebOnMessageHandler audio preflight", () => {
164176165177expect(events).toEqual(["ack", "stt"]);
166178expect(processMessageMock).toHaveBeenCalledTimes(1);
167-const [processParams] = processMessageMock.mock.calls[0] ?? [];
179+const processParams = mockObjectArg(processMessageMock, "processMessage");
168180expect(processParams.preflightAudioTranscript).toBe("transcribed voice note");
169181expect(processParams.ackAlreadySent).toBe(true);
170182expect(processParams.ackReaction).toBe(ackReactionHandle);
@@ -204,7 +216,7 @@ describe("createWebOnMessageHandler audio preflight", () => {
204216expect(transcribeFirstAudioMock).not.toHaveBeenCalled();
205217expect(maybeSendAckReactionMock).not.toHaveBeenCalled();
206218expect(processMessageMock).toHaveBeenCalledTimes(1);
207-const [processParams] = processMessageMock.mock.calls[0] ?? [];
219+const processParams = mockObjectArg(processMessageMock, "processMessage");
208220expect(processParams).not.toHaveProperty("preflightAudioTranscript");
209221expect(processParams).not.toHaveProperty("ackAlreadySent");
210222expect(processParams).not.toHaveProperty("ackReaction");
@@ -293,15 +305,15 @@ describe("createWebOnMessageHandler audio preflight", () => {
293305await handler(makeGroupAudioMsg());
294306295307expect(applyGroupGatingMock).toHaveBeenCalledTimes(2);
296-const [firstGatingParams] = applyGroupGatingMock.mock.calls[0] ?? [];
308+const firstGatingParams = mockObjectArg(applyGroupGatingMock, "applyGroupGating");
297309expect(firstGatingParams.deferMissingMention).toBe(true);
298310expect(firstGatingParams).not.toHaveProperty("mentionText");
299311expect(events).toEqual(["ack", "stt"]);
300-const [secondGatingParams] = applyGroupGatingMock.mock.calls[1] ?? [];
312+const secondGatingParams = mockObjectArg(applyGroupGatingMock, "applyGroupGating", 1);
301313expect(secondGatingParams.mentionText).toBe("transcribed voice note");
302314expect(secondGatingParams).not.toHaveProperty("deferMissingMention");
303315expect(processMessageMock).toHaveBeenCalledTimes(1);
304-const [processParams] = processMessageMock.mock.calls[0] ?? [];
316+const processParams = mockObjectArg(processMessageMock, "processMessage");
305317expect(processParams.preflightAudioTranscript).toBe("transcribed voice note");
306318expect(processParams.ackAlreadySent).toBe(true);
307319expect(processParams.ackReaction).toBe(ackReactionHandle);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。