


























@@ -185,16 +185,28 @@ type MockWithCalls = {
185185mock: { calls: unknown[][] };
186186};
187187188+function mockCallAt(mock: MockWithCalls, index = 0): unknown[] {
189+const call = mock.mock.calls[index];
190+if (!call) {
191+throw new Error(`expected mock call ${index}`);
192+}
193+return call;
194+}
195+188196function firstObjectArg(mock: MockWithCalls): Record<string, unknown> {
189-const value = mock.mock.calls[0]?.[0];
197+const value = mockCallAt(mock)[0];
190198if (value === undefined || value === null || typeof value !== "object" || Array.isArray(value)) {
191199throw new Error("expected first mock call to receive an object argument");
192200}
193201return value as Record<string, unknown>;
194202}
195203204+function continueConversationCall(mock: MockWithCalls): unknown[] {
205+return mockCallAt(mock);
206+}
207+196208function continueConversationRef(mock: MockWithCalls): Record<string, unknown> {
197-const ref = mock.mock.calls[0]?.[1];
209+const ref = continueConversationCall(mock)[1];
198210if (ref === undefined || ref === null || typeof ref !== "object" || Array.isArray(ref)) {
199211throw new Error("expected continueConversation ref object");
200212}
@@ -478,10 +490,10 @@ describe("editMessageMSTeams", () => {
478490479491expect(result.conversationId).toBe("19:conversation@thread.tacv2");
480492expect(mockContinueConversation).toHaveBeenCalledTimes(1);
481-const continueConversationCall = mockContinueConversation.mock.calls[0];
482-expect(continueConversationCall?.[0]).toBe("app-id");
493+const call = continueConversationCall(mockContinueConversation);
494+expect(call[0]).toBe("app-id");
483495expect(continueConversationRef(mockContinueConversation).activityId).toBeUndefined();
484-expect(typeof continueConversationCall?.[2]).toBe("function");
496+expect(typeof call[2]).toBe("function");
485497expect(mockUpdateActivity).toHaveBeenCalledWith({
486498type: "message",
487499id: "activity-123",
@@ -529,10 +541,10 @@ describe("deleteMessageMSTeams", () => {
529541530542expect(result.conversationId).toBe("19:conversation@thread.tacv2");
531543expect(mockContinueConversation).toHaveBeenCalledTimes(1);
532-const continueConversationCall = mockContinueConversation.mock.calls[0];
533-expect(continueConversationCall?.[0]).toBe("app-id");
544+const call = continueConversationCall(mockContinueConversation);
545+expect(call[0]).toBe("app-id");
534546expect(continueConversationRef(mockContinueConversation).activityId).toBeUndefined();
535-expect(typeof continueConversationCall?.[2]).toBe("function");
547+expect(typeof call[2]).toBe("function");
536548expect(mockDeleteActivity).toHaveBeenCalledWith("activity-456");
537549});
538550@@ -569,7 +581,7 @@ describe("deleteMessageMSTeams", () => {
569581});
570582571583// appId should be forwarded correctly
572-expect(mockContinueConversation.mock.calls[0]?.[0]).toBe("my-app-id");
584+expect(continueConversationCall(mockContinueConversation)[0]).toBe("my-app-id");
573585// activityId on the proactive ref should be cleared (undefined) — proactive pattern
574586expect(continueConversationRef(mockContinueConversation).activityId).toBeUndefined();
575587});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。