Skip to content

Commit e4c2006

Browse files
author
Carlos Atencio
committed
Adding delay option for responses. v0.6
1 parent 9aa7df1 commit e4c2006

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ The full GET schema for defining your mocks is as follows:
119119
response: {
120120
data: {}, // This is the return value for the matched request
121121
status: 500 // The HTTP status code for the mocked response. This is an optional field.
122+
delay: 2 // number of milliseconds to delay sending back the response.
122123
}
123124

124125
A full mock for a POST call takes the following options:
@@ -150,7 +151,9 @@ Defining `params`, `queryString`, `headers`, or `data` will help the plugin matc
150151
Headers must be defined as the headers that will be used in the http call. Therefore, if in the code to be tested, the headers are defined using properties with function values, these functions will be evaluated as per the $http specification and matched by end result.
151152

152153
#### Response
153-
The default `status` value is 200 if none is specified.
154+
The default `status` value is 200 if none is specified.
155+
156+
An optional `delay` value can be set on the response to assert any state that occurs when waiting for the response in your application, i.e. loading messages or spinners. Please note that UI tests with timing expectations can be somewhat unstable and provide inconsistent results. Please use this feature carefully.
154157

155158
### Precendence
156159
protractor-http-mock will respond with the **last** matched request in case there are several matches. The plugin will start matching the default mocks first, followed by those added within the test itself in the order they are added. In other words, the last mock defined will always win.

lib/httpMock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ function mockTemplate() {
234234

235235
newModule.requests.push(resolvedConfig);
236236

237-
var delay = expectation.responseDelay || 0;
237+
var delay = expectation.response.delay || 0;
238238

239239
setTimeout(function(){
240240
var resolvedResponse;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "protractor-http-mock",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"description": "Mock HTTP calls in your protractor specs.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)