diff --git a/extensions/feishu/src/bot.test.ts b/extensions/feishu/src/bot.test.ts index 813110378c3f..9ece817b30ea 100644 --- a/extensions/feishu/src/bot.test.ts +++ b/extensions/feishu/src/bot.test.ts @@ -241,8 +241,10 @@ function mockCallArg( _type?: (value: unknown) => value is T, ): T { const call = mock.mock.calls[callIndex]; - expect(call).toBeDefined(); - return call?.[argIndex] as T; + if (!call) { + throw new Error(`Expected mock call at index ${callIndex}`); + } + return call[argIndex] as T; } type FeishuRoutePeer = { id: string; kind: "direct" | "group" }; diff --git a/extensions/feishu/src/comment-dispatcher.test.ts b/extensions/feishu/src/comment-dispatcher.test.ts index de7f4783c61d..8c2521f70112 100644 --- a/extensions/feishu/src/comment-dispatcher.test.ts +++ b/extensions/feishu/src/comment-dispatcher.test.ts @@ -149,7 +149,9 @@ describe("createFeishuCommentReplyDispatcher", () => { expect(status).toBe("done"); const client = createFeishuClientMock.mock.results[0]?.value; - expect(client).toBeDefined(); + if (!client) { + throw new Error("Expected Feishu client"); + } expect(deliverCommentThreadTextMock).toHaveBeenCalledWith(client, { file_token: "doc_token_1", file_type: "docx", diff --git a/extensions/feishu/src/docx.test.ts b/extensions/feishu/src/docx.test.ts index b221c7131c29..36a063103742 100644 --- a/extensions/feishu/src/docx.test.ts +++ b/extensions/feishu/src/docx.test.ts @@ -72,8 +72,10 @@ function requireRecord(value: unknown, label: string): Record { function callArg(mock: unknown, callIndex: number, argIndex: number, label: string) { const calls = (mock as { mock?: { calls?: Array> } }).mock?.calls ?? []; const call = calls.at(callIndex); - expect(call, label).toBeDefined(); - return call?.[argIndex]; + if (!call) { + throw new Error(`Expected ${label}`); + } + return call[argIndex]; } function expectLoadWebMediaCall(fileName: string, localRoots: unknown[] | undefined) { diff --git a/extensions/feishu/src/drive.test.ts b/extensions/feishu/src/drive.test.ts index 2ab9c06929e2..ec030547c667 100644 --- a/extensions/feishu/src/drive.test.ts +++ b/extensions/feishu/src/drive.test.ts @@ -52,8 +52,10 @@ function mockCallArg( _type?: (value: unknown) => value is T, ): T { const call = mock.mock.calls[callIndex]; - expect(call).toBeDefined(); - return call?.[argIndex] as T; + if (!call) { + throw new Error(`Expected mock call at index ${callIndex}`); + } + return call[argIndex] as T; } type FeishuDriveRequest = { @@ -633,7 +635,9 @@ describe("registerFeishuDriveTools", () => { client?: unknown; deliveryContext?: { channel?: string; threadId?: string; to?: string }; }>(cleanupAmbientCommentTypingReactionMock, 0, 0); - expect(cleanupRequest.client).toBeDefined(); + if (!cleanupRequest.client) { + throw new Error("Expected cleanup request client"); + } expect(cleanupRequest.deliveryContext).toEqual({ channel: "feishu", to: "comment:docx:doc_1:c1", @@ -707,7 +711,9 @@ describe("registerFeishuDriveTools", () => { client?: unknown; deliveryContext?: { channel?: string; threadId?: string; to?: string }; }>(cleanupAmbientCommentTypingReactionMock, 0, 0); - expect(cleanupRequest.client).toBeDefined(); + if (!cleanupRequest.client) { + throw new Error("Expected cleanup request client"); + } expect(cleanupRequest.deliveryContext).toEqual({ channel: "feishu", to: "comment:docx:doc_1:c1", diff --git a/extensions/feishu/src/media.test.ts b/extensions/feishu/src/media.test.ts index d3f3403dcfad..7a2471e74abb 100644 --- a/extensions/feishu/src/media.test.ts +++ b/extensions/feishu/src/media.test.ts @@ -91,8 +91,10 @@ function mockCallArg( _type?: (value: unknown) => value is T, ): T { const call = mock.mock.calls[callIndex]; - expect(call).toBeDefined(); - return call?.[argIndex] as T; + if (!call) { + throw new Error(`Expected mock call at index ${callIndex}`); + } + return call[argIndex] as T; } function callData( @@ -101,7 +103,9 @@ function callData( _type?: (value: unknown) => value is T, ): T { const arg = mockCallArg<{ data?: unknown }>(mock, callIndex, 0); - expect(arg.data).toBeDefined(); + if (arg.data === undefined) { + throw new Error(`Expected mock call data at index ${callIndex}`); + } return arg.data as T; } diff --git a/extensions/feishu/src/outbound.test.ts b/extensions/feishu/src/outbound.test.ts index 70ba933b1ab4..3f1cc11d82d8 100644 --- a/extensions/feishu/src/outbound.test.ts +++ b/extensions/feishu/src/outbound.test.ts @@ -801,8 +801,11 @@ describe("feishuOutbound comment-thread routing", () => { expect(status).toBe("done"); expect(deliverCommentThreadTextMock).toHaveBeenCalled(); - expect(cleanupReactionCall()?.client).toBeDefined(); - expect(cleanupReactionCall()?.deliveryContext).toEqual({ + const cleanupCall = cleanupReactionCall(); + if (!cleanupCall?.client) { + throw new Error("Expected cleanup reaction client"); + } + expect(cleanupCall.deliveryContext).toEqual({ channel: "feishu", to: "comment:docx:doxcn123:7623358762119646411", threadId: "reply_ambient_1", diff --git a/extensions/feishu/src/reply-dispatcher.test.ts b/extensions/feishu/src/reply-dispatcher.test.ts index edcc4e4bfaf3..eb29a139c012 100644 --- a/extensions/feishu/src/reply-dispatcher.test.ts +++ b/extensions/feishu/src/reply-dispatcher.test.ts @@ -245,7 +245,9 @@ describe("createFeishuReplyDispatcher streaming behavior", () => { expected: Record, ): Record { const start = streamingInstances[instanceIndex]?.start; - expect(start, "streaming instance must exist").toBeDefined(); + if (!start) { + throw new Error(`Expected streaming instance ${instanceIndex}`); + } expect(start.mock.calls[0]?.[0]).toBe("oc_chat"); expect(start.mock.calls[0]?.[1]).toBe("chat_id"); return expectRecordFields(start.mock.calls[0]?.[2], "streaming start options", expected);