

























@@ -18,6 +18,14 @@ const failingResolve = async () => {
1818throw new Error("DNS failure");
1919};
202021+const firstFetchCall = (fetchFn: ReturnType<typeof vi.fn<typeof fetch>>) => {
22+const [call] = fetchFn.mock.calls;
23+if (!call) {
24+throw new Error("expected fetch call");
25+}
26+return call;
27+};
28+2129// ─── isPrivateOrReservedIP ───────────────────────────────────────────────────
22302331describe("isPrivateOrReservedIP", () => {
@@ -272,7 +280,7 @@ describe("uploadToConsentUrl", () => {
272280});
273281274282expect(fetchFn).toHaveBeenCalledOnce();
275-const [url, opts] = fetchFn.mock.calls[0];
283+const [url, opts] = firstFetchCall(fetchFn);
276284expect(url).toBe("https://contoso.sharepoint.com/upload");
277285expect(opts?.method).toBe("PUT");
278286expect(opts?.headers).toEqual({
@@ -312,7 +320,7 @@ describe("uploadToConsentUrl", () => {
312320});
313321314322it("allows upload to a valid SharePoint URL and performs PUT", async () => {
315-const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200 });
323+const mockFetch = vi.fn<typeof fetch>(async () => new Response(null, { status: 200 }));
316324const buffer = Buffer.from("file content");
317325318326await uploadToConsentUrl({
@@ -324,10 +332,14 @@ describe("uploadToConsentUrl", () => {
324332});
325333326334expect(mockFetch).toHaveBeenCalledOnce();
327-const [url, opts] = mockFetch.mock.calls[0];
335+const [url, opts] = firstFetchCall(mockFetch);
328336expect(url).toBe("https://contoso.sharepoint.com/sites/uploads/file.pdf");
329-expect(opts.method).toBe("PUT");
330-expect(opts.headers["Content-Type"]).toBe("application/pdf");
337+expect(opts?.method).toBe("PUT");
338+expect(opts?.headers).toEqual(
339+expect.objectContaining({
340+"Content-Type": "application/pdf",
341+}),
342+);
331343});
332344333345it("throws on non-OK response after passing validation", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。