
























@@ -54,6 +54,14 @@ describe("native PDF provider API calls", () => {
5454return fetchMock;
5555};
565657+const firstFetchCall = (fetchMock: { mock: { calls: unknown[][] } }): unknown[] => {
58+const call = fetchMock.mock.calls.at(0);
59+if (!call) {
60+throw new Error("expected fetch to be called");
61+}
62+return call;
63+};
64+5765afterEach(() => {
5866global.fetch = priorFetch;
5967});
@@ -76,7 +84,10 @@ describe("native PDF provider API calls", () => {
76847785expect(result).toBe("Analysis of PDF");
7886expect(fetchMock).toHaveBeenCalledTimes(1);
79-const [url, opts] = fetchMock.mock.calls[0];
87+const [url, opts] = firstFetchCall(fetchMock) as [
88+string,
89+{ body: string; signal: AbortSignal },
90+];
8091expect(url).toContain("/v1/messages");
8192expect(opts.signal).toBeInstanceOf(AbortSignal);
8293expect(opts.signal.aborted).toBe(false);
@@ -131,7 +142,10 @@ describe("native PDF provider API calls", () => {
131142132143expect(result).toBe("Gemini PDF analysis");
133144expect(fetchMock).toHaveBeenCalledTimes(1);
134-const [url, opts] = fetchMock.mock.calls[0];
145+const [url, opts] = firstFetchCall(fetchMock) as [
146+string,
147+{ body: string; headers: Record<string, string>; signal: AbortSignal },
148+];
135149expect(url).toContain("generateContent");
136150expect(url).toContain("gemini-2.5-pro");
137151expect(url).not.toContain("?key=");
@@ -187,7 +201,8 @@ describe("native PDF provider API calls", () => {
187201}),
188202);
189203190-const body = JSON.parse(fetchMock.mock.calls[0][1].body);
204+const [, opts] = firstFetchCall(fetchMock) as [unknown, { body: string }];
205+const body = JSON.parse(opts.body);
191206expect(body.messages[0].content).toHaveLength(3);
192207expect(body.messages[0].content[0].type).toBe("document");
193208expect(body.messages[0].content[1].type).toBe("document");
@@ -206,7 +221,7 @@ describe("native PDF provider API calls", () => {
206221makeAnthropicAnalyzeParams({ baseUrl: "https://custom.example.com" }),
207222);
208223209-expect(fetchMock.mock.calls[0][0]).toContain("https://custom.example.com/v1/messages");
224+expect(firstFetchCall(fetchMock)[0]).toContain("https://custom.example.com/v1/messages");
210225});
211226212227it("anthropicAnalyzePdf requires apiKey", async () => {
@@ -235,7 +250,7 @@ describe("native PDF provider API calls", () => {
235250}),
236251);
237252238-const [url] = fetchMock.mock.calls[0];
253+const [url] = firstFetchCall(fetchMock);
239254expect(url).toContain("/v1beta/models/");
240255expect(url).not.toContain("/v1beta/v1beta");
241256});
@@ -254,7 +269,7 @@ describe("native PDF provider API calls", () => {
254269}),
255270);
256271257-const [url] = fetchMock.mock.calls[0];
272+const [url] = firstFetchCall(fetchMock);
258273expect(url).toContain("https://generativelanguage.googleapis.com/v1beta/models/");
259274expect(url).not.toContain("/v1beta/v1beta");
260275});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。