You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
# Protractor Mock
2
-
A NodeJS module to be used alongside [Protractor](https://github.com/angular/protractor) to facilitate setting up mocks for HTTP calls for the AngularJS applications under test.
2
+
A NodeJS module to be used alongside [Protractor](https://github.com/angular/protractor) to facilitate setting up mocks for HTTP calls for the AngularJS applications under test.
3
3
4
4
This allows the developer to isolate the UI and client-side application code in our tests without any dependencies on an API.
5
5
@@ -69,11 +69,11 @@ Make sure to clean up after test execution. This should be typically done in the
69
69
afterEach(function(){
70
70
mock.teardown();
71
71
});
72
-
72
+
73
73
Please note that the `mock()` function needs to be called before the browser opens. If you have different mock data for different tests, please make sure that, either the tests always start in a new browser window, or that its possible to setup all the mocks for each test case before any of tests start running.
74
74
75
75
### Mock files
76
-
Mocks can also be loaded from physical files located in the `mocks.dir` directory that we defined in our configuration:
76
+
Mocks can also be loaded from physical files located in the `mocks.dir` directory that we defined in our configuration:
77
77
78
78
tests
79
79
e2e
@@ -103,6 +103,7 @@ The full GET schema for defining your mocks is as follows:
103
103
request: {
104
104
path: '/products/1/items',
105
105
method: 'GET',
106
+
regex: false, // Boolean to enable Regular Expression matching on path. This is an optional field.
106
107
params: { // These match params as they would be passed to the $http service. This is an optional field.
107
108
page: 2,
108
109
status: 'onsale'
@@ -127,6 +128,7 @@ A full mock for a POST call takes the following options:
127
128
request: {
128
129
path: '/products/1/items',
129
130
method: 'POST',
131
+
regex: false, // Boolean to enable Regular Expression matching on path. This is an optional field.
130
132
data: { // These match POST data. This is an optional field.
131
133
status: 'onsale',
132
134
title: 'Blue Jeans',
@@ -151,7 +153,7 @@ Defining `params`, `queryString`, `headers`, or `data` will help the plugin matc
151
153
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.
152
154
153
155
#### Response
154
-
The default `status` value is 200 if none is specified.
156
+
The default `status` value is 200 if none is specified.
155
157
156
158
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.
157
159
@@ -212,7 +214,7 @@ These will dynamically modify your current set of mocks, and any new request tha
212
214
213
215
Plugins can be used to extend the matching functionality of protractor-http-mock. These are separate from protractor plugins.
214
216
215
-
A plugin can be defined as either an NPM package or a function.
217
+
A plugin can be defined as either an NPM package or a function.
216
218
217
219
They can be declared in your protractor configuration to be consumed by all your tests:
218
220
@@ -225,7 +227,7 @@ They can be declared in your protractor configuration to be consumed by all your
225
227
}
226
228
227
229
or in each individual test:
228
-
230
+
229
231
mock([
230
232
//mocks go here
231
233
], [
@@ -243,7 +245,7 @@ See this [sample plugin](https://github.com/atecarlos/protractor-http-mock-sampl
243
245
### Defaults
244
246
245
247
If necessary, default mocks and plugins can be skipped for a particular test simply by passing true at the end of your `mock` call:
0 commit comments