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