forked from jefflau/jest-fetch-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
46 lines (38 loc) · 1.37 KB
/
index.d.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
// TypeScript Version: 2.3
import Global = NodeJS.Global;
import "jest";
declare global {
const fetchMock: FetchMock;
namespace NodeJS {
interface Global {
fetch: FetchMock;
}
}
}
export interface GlobalWithFetchMock extends Global {
fetchMock: FetchMock;
fetch: FetchMock;
}
export interface FetchMock extends jest.MockInstance<any, any[]> {
(input?: string | Request, init?: RequestInit): Promise<Response>;
mockResponse(body: BodyOrFunction, init?: MockParams): FetchMock;
mockResponseOnce(body: BodyOrFunction, init?: MockParams): FetchMock;
once(body: BodyOrFunction, init?: MockParams): FetchMock;
mockResponses(...responses: Array<(BodyOrFunction | [BodyOrFunction, MockParams])>): FetchMock;
mockReject(error?: ErrorOrFunction): FetchMock;
mockRejectOnce(error?: ErrorOrFunction): FetchMock;
resetMocks(): void;
}
// reference: https://github.github.io/fetch/#Response
export interface MockParams {
status?: number;
statusText?: string;
headers?: string[][] | { [key: string]: string }; // HeadersInit
url?: string;
}
export interface MockResponseInit extends MockParams {
body?: string;
}
export type BodyOrFunction = string | MockResponseInitFunction;
export type ErrorOrFunction = Error | MockResponseInitFunction;
export type MockResponseInitFunction = () => Promise<MockResponseInit>;