-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathtypescript.test.ts
More file actions
58 lines (52 loc) 路 1.57 KB
/
Copy pathtypescript.test.ts
File metadata and controls
58 lines (52 loc) 路 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import unfetch, { Unfetch } from "..";
import isomorphicUnfetch from "../packages/isomorphic-unfetch";
describe("TypeScript", () => {
describe("browser", () => {
beforeAll(() => {
function XMLHttpRequest() {
const res = {
setRequestHeader: jest.fn(),
getAllResponseHeaders: jest.fn().mockReturnValue(""),
getResponseHeader: jest.fn().mockReturnValue(""),
open: jest.fn((method, url) => {
res.responseURL = url;
}),
send: jest.fn(),
status: 200,
statusText: "OK",
get responseText() {
return this.responseURL.replace(/^data:\,/, "");
},
responseURL: null,
onload: () => {},
};
setTimeout(() => res.onload());
return res;
}
// @ts-ignore-next-line
global.XMLHttpRequest = jest.fn(XMLHttpRequest);
});
it("should have valid TypeScript types", async () => {
const res: Unfetch.Response = await unfetch("data:,test");
const text = await res.text();
expect(text).toBe("test");
});
// This fails because we're abusing Arrays as iterables:
// it("should allow cast to Response", async () => {
// const res: Response = await unfetch("data:,test");
// const r = res.headers.keys()[0]
// });
});
describe("isomorphic-unfetch", () => {
it("should allow use of standard types like Response", async () => {
const res: Response = await isomorphicUnfetch(new URL("data:,test"));
const blob: Blob = await res.blob();
});
it("should accept Headers", async () => {
isomorphicUnfetch("data:,test", {
headers: new Headers({ a: "b" }),
mode: "cors",
});
});
});
});