@@ -997,8 +997,10 @@ angular.mock.dump = function(object) {
997
997
* Fake HTTP backend implementation suitable for unit testing applications that use the
998
998
* {@link ng.$http $http service}.
999
999
*
1000
- * *Note*: For fake HTTP backend implementation suitable for end-to-end testing or backend-less
1000
+ * <div class="alert alert-info">
1001
+ * **Note**: For fake HTTP backend implementation suitable for end-to-end testing or backend-less
1001
1002
* development please see {@link ngMockE2E.$httpBackend e2e $httpBackend mock}.
1003
+ * </div>
1002
1004
*
1003
1005
* During unit testing, we want our unit tests to run quickly and have no external dependencies so
1004
1006
* we don’t want to send [XHR](https://developer.mozilla.org/en/xmlhttprequest) or
@@ -2288,8 +2290,10 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2288
2290
* Fake HTTP backend implementation suitable for end-to-end testing or backend-less development of
2289
2291
* applications that use the {@link ng.$http $http service}.
2290
2292
*
2291
- * *Note*: For fake http backend implementation suitable for unit testing please see
2293
+ * <div class="alert alert-info">
2294
+ * **Note**: For fake http backend implementation suitable for unit testing please see
2292
2295
* {@link ngMock.$httpBackend unit-testing $httpBackend mock}.
2296
+ * </div>
2293
2297
*
2294
2298
* This implementation can be used to respond with static or dynamic responses via the `when` api
2295
2299
* and its shortcuts (`whenGET`, `whenPOST`, etc) and optionally pass through requests to the
@@ -2310,9 +2314,9 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2310
2314
* on the `ngMockE2E` and your application modules and defines the fake backend:
2311
2315
*
2312
2316
* ```js
2313
- * myAppDev = angular.module('myAppDev', ['myApp', 'ngMockE2E']);
2317
+ * var myAppDev = angular.module('myAppDev', ['myApp', 'ngMockE2E']);
2314
2318
* myAppDev.run(function($httpBackend) {
2315
- * phones = [{name: 'phone1'}, {name: 'phone2'}];
2319
+ * var phones = [{name: 'phone1'}, {name: 'phone2'}];
2316
2320
*
2317
2321
* // returns the current list of phones
2318
2322
* $httpBackend.whenGET('/phones').respond(phones);
@@ -2323,12 +2327,74 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
2323
2327
* phones.push(phone);
2324
2328
* return [200, phone, {}];
2325
2329
* });
2326
- * $httpBackend.whenGET(/^\/templates\//).passThrough();
2330
+ * $httpBackend.whenGET(/^\/templates\//).passThrough(); // Requests for templare are handled by the real server
2327
2331
* //...
2328
2332
* });
2329
2333
* ```
2330
2334
*
2331
2335
* Afterwards, bootstrap your app with this new module.
2336
+ *
2337
+ * ## Example
2338
+ * <example name="httpbackend-e2e-testing" module="myAppE2E" deps="angular-mocks.js">
2339
+ * <file name="app.js">
2340
+ * var myApp = angular.module('myApp', []);
2341
+ *
2342
+ * myApp.controller('main', function($http) {
2343
+ * var ctrl = this;
2344
+ *
2345
+ * ctrl.phones = [];
2346
+ * ctrl.newPhone = {
2347
+ * name: ''
2348
+ * };
2349
+ *
2350
+ * ctrl.getPhones = function() {
2351
+ * $http.get('/phones').then(function(response) {
2352
+ * ctrl.phones = response.data;
2353
+ * });
2354
+ * };
2355
+ *
2356
+ * ctrl.addPhone = function(phone) {
2357
+ * $http.post('/phones', phone).then(function() {
2358
+ * ctrl.newPhone = {name: ''};
2359
+ * return ctrl.getPhones();
2360
+ * });
2361
+ * };
2362
+ *
2363
+ * ctrl.getPhones();
2364
+ * });
2365
+ * </file>
2366
+ * <file name="e2e.js">
2367
+ * var myAppDev = angular.module('myAppE2E', ['myApp', 'ngMockE2E']);
2368
+ *
2369
+ * myAppDev.run(function($httpBackend) {
2370
+ * var phones = [{name: 'phone1'}, {name: 'phone2'}];
2371
+ *
2372
+ * // returns the current list of phones
2373
+ * $httpBackend.whenGET('/phones').respond(phones);
2374
+ *
2375
+ * // adds a new phone to the phones array
2376
+ * $httpBackend.whenPOST('/phones').respond(function(method, url, data) {
2377
+ * var phone = angular.fromJson(data);
2378
+ * phones.push(phone);
2379
+ * return [200, phone, {}];
2380
+ * });
2381
+ * });
2382
+ * </file>
2383
+ * <file name="index.html">
2384
+ * <div ng-controller="main as $ctrl">
2385
+ * <form name="newPhoneForm" ng-submit="$ctrl.addPhone($ctrl.newPhone)">
2386
+ * <input type="text" ng-model="$ctrl.newPhone.name">
2387
+ * <input type="submit" value="Add Phone">
2388
+ * </form>
2389
+ * <h1>Phones</h1>
2390
+ * <ul>
2391
+ * <li ng-repeat="phone in $ctrl.phones">{{phone.name}}</li>
2392
+ * </ul>
2393
+ * </div>
2394
+ * </file>
2395
+ * </example>
2396
+ *
2397
+ *
2332
2398
*/
2333
2399
2334
2400
/**
0 commit comments