-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmock-fetch.type.ts
49 lines (43 loc) · 1022 Bytes
/
mock-fetch.type.ts
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
export type Fetch = (
input: URL | Request | string,
init?: RequestInit,
) => Promise<Response>;
export interface MockRequestInit
extends Omit<RequestInit, "method" | "body" | "headers"> {
method?: MockMatcher;
body?: BodyInit | null | MockMatcher;
headers?: MockHeadersInit;
}
export type MockHeadersInit = Headers | Record<string, MockMatcher> | [
string,
MockMatcher,
][] | ((headers: Headers) => boolean);
export interface RequestKey {
url: URL;
method: string;
headers: Headers;
query?: URLSearchParams;
body?: string;
}
export interface MockRequestInputs {
input: URL | Request | MockMatcher;
init?: MockRequestInit;
url: MockMatcher;
method: MockMatcher;
body?: MockMatcher;
}
export interface MockRequest {
request: MockRequestInputs;
response: Response;
error?: Error;
consumed: boolean;
pending: boolean;
persist: boolean;
times: number;
delay: number;
calls: number;
}
export type MockMatcher =
| string
| ((input: string) => boolean)
| RegExp;