Skip to content

Commit

Permalink
fix fetch browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Oct 28, 2024
1 parent 15858dd commit 6f2c832
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/fetch-http-handler/src/fetch-http-handler.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@ import { createRequest } from "./create-request";
import { FetchHttpHandler, keepAliveSupport } from "./fetch-http-handler";

vi.mock("./create-request", async () => {
const actual: any = await vi.importActual("./create-request");
return {
createRequest: vi.fn().mockImplementation(actual.createRequest),
createRequest: vi.fn().mockImplementation((_url, options) => {
const url = new URL(_url);
return {
protocol: url.protocol,
hostname: url.hostname,
...options,
} as any;
}),
};
});

vi.spyOn(global, "fetch").mockImplementation((async () => {
return {
headers: {
entries() {
return [];
},
},
async blob() {
return undefined;
},
};
}) as any);

(typeof Blob === "function" ? describe : describe.skip)(FetchHttpHandler.name, () => {
interface MockHttpRequestOptions {
method?: string;
Expand All @@ -23,7 +42,7 @@ vi.mock("./create-request", async () => {
}

const getMockHttpRequest = (options: MockHttpRequestOptions): HttpRequest =>
new HttpRequest({ hostname: "example.com", ...options });
new HttpRequest({ hostname: "localhost", protocol: "http", ...options });

describe("fetch", () => {
beforeAll(() => {
Expand Down

0 comments on commit 6f2c832

Please sign in to comment.