forked from jbaroudi/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protractor-http-mock.d.ts
209 lines (189 loc) · 5.5 KB
/
protractor-http-mock.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Type definitions for protractor-http-mock
// Project: https://github.com/atecarlos/protractor-http-mock
// Definitions by: Crevil <https://github.com/Crevil>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../selenium-webdriver/selenium-webdriver.d.ts" />
declare module mock {
interface ProtractorHttpMock {
/**
* Instantiate mock module. This must be done before the browser connects.
*
* @param mocks An array of mock modules to load into the application.
* @param skipDefaults Set true to skip loading of default mocks.
*/
<T>(mocks?: Array<requests.BaseRequest<T>>, skipDefaults?: boolean): ProtractorHttpMock;
/**
* Instantiate mock modules from files. This must be done before the browser connects.
*
* @param mocks An array of mock module names relative to the rootDirectory configuration.
*/
(mocks: Array<string>): ProtractorHttpMock;
/**
* Clean up.
* Typically done in the afterEach call to ensure the teardown
* is executed regardless of what happens in the test execution.
*/
teardown(): void;
/**
* Returns a promise that will be resolved with an array of
* all matched HTTP requests.
*/
requestsMade(): webdriver.promise.Promise<Array<ReceivedRequest>>;
/**
* Returns a promise that will be resolved with a true boolean
* when all matched HTTP requests are cleared.
*/
clearRequests(): webdriver.promise.Promise<boolean>;
/**
* Module configuration to setup
*/
config: {
/**
* Mocks directory where mock files are located.
* Default: process.cwd()
*/
rootDirectory?: string;
/**
* Path to protractor configuration file.
* Default: protractor.conf
*/
protractorConfig?: string;
};
}
/**
* Matched request.
*/
interface ReceivedRequest {
url: string;
method: string;
}
module requests {
/**
* Base request mock used for all mocks.
*/
interface BaseRequest<TResponse> {
request: {
method: string;
path: string;
};
response: {
status: number;
data: TResponse;
};
}
/**
* GET request mock.
*/
interface Get<TResponse> extends BaseRequest<TResponse> {
request: {
method: string;
path: string;
params?: Object;
queryString?: Object;
headers?: Object;
interceptedRequest?: boolean;
interceptedAnonymousRequest?: boolean;
};
response: {
status: number;
data: TResponse;
};
}
/**
* POST request mock with payload.
*/
interface PostData<TResponse, TPayload> extends BaseRequest<TResponse> {
request: {
path: string;
method: string;
data: TPayload;
};
response: {
status: number;
data: TResponse;
};
}
/**
* POST request mock.
*/
interface Post<TResponse> extends BaseRequest<TResponse> {
request: {
path: string;
method: string;
};
response: {
status: number;
data: TResponse;
};
}
/**
* HEAD request mock.
*/
interface Head<TResponse> extends BaseRequest<TResponse> {
request: {
path: string;
method: string;
};
response: {
status: number;
data: TResponse;
};
}
/**
* HTTP Delete request mock.
*/
interface Delete<TResponse> extends BaseRequest<TResponse> {
request: {
path: string;
method: string;
};
response: {
status: number;
data: TResponse;
};
}
/**
* PUT request mock.
*/
interface Put<TResponse> extends BaseRequest<TResponse> {
request: {
path: string;
method: string;
};
response: {
status: number;
data: TResponse;
};
}
/**
* PATCH request mock.
*/
interface Patch<TResponse> extends BaseRequest<TResponse> {
request: {
path: string;
method: string;
};
response: {
status: number;
data: TResponse;
};
}
/**
* JSONP request mock.
*/
interface Jsonp<TResponse> extends BaseRequest<TResponse> {
request: {
path: string;
method: string;
};
response: {
status: number;
data: TResponse;
};
}
}
}
declare var mock: mock.ProtractorHttpMock;
declare module 'protractor-http-mock' {
export = mock;
}