Skip to content

Commit 6f2c832

Browse files
committed
fix fetch browser tests
1 parent 15858dd commit 6f2c832

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

packages/fetch-http-handler/src/fetch-http-handler.browser.spec.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,31 @@ import { createRequest } from "./create-request";
66
import { FetchHttpHandler, keepAliveSupport } from "./fetch-http-handler";
77

88
vi.mock("./create-request", async () => {
9-
const actual: any = await vi.importActual("./create-request");
109
return {
11-
createRequest: vi.fn().mockImplementation(actual.createRequest),
10+
createRequest: vi.fn().mockImplementation((_url, options) => {
11+
const url = new URL(_url);
12+
return {
13+
protocol: url.protocol,
14+
hostname: url.hostname,
15+
...options,
16+
} as any;
17+
}),
1218
};
1319
});
1420

21+
vi.spyOn(global, "fetch").mockImplementation((async () => {
22+
return {
23+
headers: {
24+
entries() {
25+
return [];
26+
},
27+
},
28+
async blob() {
29+
return undefined;
30+
},
31+
};
32+
}) as any);
33+
1534
(typeof Blob === "function" ? describe : describe.skip)(FetchHttpHandler.name, () => {
1635
interface MockHttpRequestOptions {
1736
method?: string;
@@ -23,7 +42,7 @@ vi.mock("./create-request", async () => {
2342
}
2443

2544
const getMockHttpRequest = (options: MockHttpRequestOptions): HttpRequest =>
26-
new HttpRequest({ hostname: "example.com", ...options });
45+
new HttpRequest({ hostname: "localhost", protocol: "http", ...options });
2746

2847
describe("fetch", () => {
2948
beforeAll(() => {

0 commit comments

Comments
 (0)