1 | import { AxiosInstance, AxiosRequestConfig } from "axios";
|
2 |
|
3 | interface Item {
|
4 | response?: any;
|
5 | responseText?: string | undefined;
|
6 | status?: number | undefined;
|
7 | statusText?: string | undefined;
|
8 | headers?: any;
|
9 | }
|
10 |
|
11 | declare class Tracker {
|
12 | constructor();
|
13 |
|
14 | /**
|
15 | * Reset all the items being tracked
|
16 | */
|
17 | reset(): void;
|
18 |
|
19 | /**
|
20 | * Add an item to be tracked
|
21 | *
|
22 | * @param item An item to be tracked
|
23 | */
|
24 | track(item: Item): void;
|
25 |
|
26 | /**
|
27 | * The count of items being tracked
|
28 | */
|
29 | count(): number;
|
30 |
|
31 | /**
|
32 | * Get an item being tracked at a given index
|
33 | *
|
34 | * @param index The index for the item to retrieve
|
35 | */
|
36 | at(index: number): Request;
|
37 |
|
38 | /**
|
39 | * Get the first item being tracked
|
40 | */
|
41 | first(): Request;
|
42 |
|
43 | /**
|
44 | * Get the most recent (last) item being tracked
|
45 | */
|
46 | mostRecent(): Request;
|
47 |
|
48 | /**
|
49 | * Dump the items being tracked to the console.
|
50 | */
|
51 | debug(): void;
|
52 |
|
53 | /**
|
54 | * Find and return element given the HTTP method and the URL.
|
55 | */
|
56 | get(method: string, url?: string): Request;
|
57 |
|
58 | /**
|
59 | * Stop an element from being tracked by removing it. Finds and returns the element,
|
60 | * given the HTTP method and the URL.
|
61 | */
|
62 | remove(method: string, url: string): Request;
|
63 | }
|
64 |
|
65 | declare class Request {
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | constructor(resolve: (arg: any) => void, reject: (arg: any) => void, config: AxiosRequestConfig);
|
74 |
|
75 | config: AxiosRequestConfig;
|
76 | headers: any;
|
77 | url: string;
|
78 | timeout: number;
|
79 | withCredentials: boolean;
|
80 | responseType: string;
|
81 |
|
82 | /**
|
83 | * Respond to this request with a timeout result
|
84 | *
|
85 | * @return A Promise that rejects with a timeout result
|
86 | */
|
87 | respondWithTimeout(): Promise<Response>;
|
88 |
|
89 | /**
|
90 | * Respond to this request with a specified result
|
91 | *
|
92 | * @param res The data representing the result of the request
|
93 | * @return A Promise that resolves once the response is ready
|
94 | */
|
95 | respondWith(res: Item): Promise<Response>;
|
96 | }
|
97 |
|
98 | declare class Response {
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | constructor(req: Request, res: any);
|
106 |
|
107 | config: AxiosRequestConfig;
|
108 | data?: any;
|
109 | status?: number | undefined;
|
110 | statusText?: string | undefined;
|
111 | headers: any;
|
112 | request: Request;
|
113 | code?: string | undefined;
|
114 | }
|
115 |
|
116 | declare let moxios: {
|
117 | stubs: Tracker;
|
118 | requests: Tracker;
|
119 | delay: number;
|
120 | timeoutException: Error;
|
121 |
|
122 | |
123 |
|
124 |
|
125 | install(instance?: AxiosInstance): void;
|
126 |
|
127 | |
128 |
|
129 |
|
130 | uninstall(instance?: AxiosInstance): void;
|
131 |
|
132 | |
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | stubRequest(urlOrRegExp: string | RegExp, response: Item): void;
|
139 |
|
140 | |
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | stubRequest(method: string, urlOrRegExp: string | RegExp, response: Item): void;
|
148 |
|
149 | |
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | stubOnce(method: string, urlOrRegExp: string | RegExp, response: Item): Promise<void>;
|
158 |
|
159 | |
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | stubFailure(method: string, urlOrRegExp: string | RegExp, response: Item): Promise<void>;
|
169 |
|
170 | |
171 |
|
172 |
|
173 |
|
174 |
|
175 | stubTimeout(urlOrRegExp: string | RegExp): string;
|
176 |
|
177 | |
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 | withMock(fn: () => void): void;
|
185 |
|
186 | |
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | wait(fn: () => void, delay?: number): void;
|
195 | };
|
196 |
|
197 | export = moxios;
|