forked from pretenderjs/pretender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
57 lines (47 loc) · 1.77 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
47
48
49
50
51
52
53
54
55
56
57
import FakeXMLHttpRequest from 'fake-xml-http-request';
import { Params, QueryParams } from 'route-recognizer';
type SetupCallback = (this: Server) => void;
interface SetupConfig {
forcePassthrough: boolean;
}
export type Config = SetupCallback | SetupConfig;
export class Server {
public passthrough: ResponseHandler;
constructor(config?: Config);
// HTTP request verbs
public get: RequestHandler;
public put: RequestHandler;
public post: RequestHandler;
public patch: RequestHandler;
public delete: RequestHandler;
public options: RequestHandler;
public head: RequestHandler;
public shutdown(): void;
public map(maps: Function): void;
public handledRequest(verb: string, path: string, request: FakeXMLHttpRequest & ExtraRequestData): void;
public unhandledRequest(verb: string, path: string, request: FakeXMLHttpRequest & ExtraRequestData): void;
public passthroughRequest(verb: string, path: string, request: FakeXMLHttpRequest & ExtraRequestData): void;
public erroredRequest(verb: string, path: string, request: FakeXMLHttpRequest & ExtraRequestData, error: Error): void;
public prepareBody(body: string): string;
public prepareHeaders(headers: {[k: string]: string}): {[k: string]: string};
}
export type RequestHandler = (
urlExpression: string,
response: ResponseHandler,
asyncOrDelay?: boolean | number
) => ResponseHandlerInstance;
export type ResponseData = [number, { [k: string]: string }, string];
interface ExtraRequestData {
params: Params;
queryParams: QueryParams;
}
export type ResponseHandler = {
(request: FakeXMLHttpRequest & ExtraRequestData):
| ResponseData
| PromiseLike<ResponseData>;
};
export type ResponseHandlerInstance = ResponseHandler & {
async: boolean;
numberOfCalls: number;
}
export default Server;