Skip to content

Commit 3ce88e0

Browse files
committed
fix fetch browser tests
1 parent 15858dd commit 3ce88e0

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
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(() => {

yarn.lock

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,6 @@ __metadata:
22872287
"@types/node": ^16.18.96
22882288
concurrently: 7.0.0
22892289
downlevel-dts: 0.10.1
2290-
nock: ^13.0.2
22912290
rimraf: 3.0.2
22922291
tslib: ^2.6.2
22932292
typedoc: 0.23.23
@@ -7582,13 +7581,6 @@ __metadata:
75827581
languageName: node
75837582
linkType: hard
75847583

7585-
"json-stringify-safe@npm:^5.0.1":
7586-
version: 5.0.1
7587-
resolution: "json-stringify-safe@npm:5.0.1"
7588-
checksum: 48ec0adad5280b8a96bb93f4563aa1667fd7a36334f79149abd42446d0989f2ddc58274b479f4819f1f00617957e6344c886c55d05a4e15ebb4ab931e4a6a8ee
7589-
languageName: node
7590-
linkType: hard
7591-
75927584
"json5@npm:^2.2.2, json5@npm:^2.2.3":
75937585
version: 2.2.3
75947586
resolution: "json5@npm:2.2.3"
@@ -8174,18 +8166,6 @@ __metadata:
81748166
languageName: node
81758167
linkType: hard
81768168

8177-
"nock@npm:^13.0.2":
8178-
version: 13.3.1
8179-
resolution: "nock@npm:13.3.1"
8180-
dependencies:
8181-
debug: ^4.1.0
8182-
json-stringify-safe: ^5.0.1
8183-
lodash: ^4.17.21
8184-
propagate: ^2.0.0
8185-
checksum: 0f2a73e8432f6b5650656c53eef99f9e5bbde3df538dc2f07057edc4438cfc61a394c9d06dd82e60f6e86d42433f20f3c04364a1f088beee7bf03a24e3f0fdd0
8186-
languageName: node
8187-
linkType: hard
8188-
81898169
"node-fetch@npm:2.6.7":
81908170
version: 2.6.7
81918171
resolution: "node-fetch@npm:2.6.7"
@@ -8756,13 +8736,6 @@ __metadata:
87568736
languageName: node
87578737
linkType: hard
87588738

8759-
"propagate@npm:^2.0.0":
8760-
version: 2.0.1
8761-
resolution: "propagate@npm:2.0.1"
8762-
checksum: c4febaee2be0979e82fb6b3727878fd122a98d64a7fa3c9d09b0576751b88514a9e9275b1b92e76b364d488f508e223bd7e1dcdc616be4cdda876072fbc2a96c
8763-
languageName: node
8764-
linkType: hard
8765-
87668739
"proxy-from-env@npm:1.1.0":
87678740
version: 1.1.0
87688741
resolution: "proxy-from-env@npm:1.1.0"

0 commit comments

Comments
 (0)