Skip to content

Commit b9f19ad

Browse files
authored
docs(ngMockE2E): add docs for $httpBackend.matchLatestDefinitionEnabled()
Closes angular#16577
1 parent 0b1adbb commit b9f19ad

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/ngMock/angular-mocks.js

+33
Original file line numberDiff line numberDiff line change
@@ -2756,6 +2756,39 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
27562756
* control how a matched request is handled. You can save this object for later use and invoke
27572757
* `respond` or `passThrough` again in order to change how a matched request is handled.
27582758
*/
2759+
/**
2760+
* @ngdoc method
2761+
* @name $httpBackend#matchLatestDefinition
2762+
* @module ngMockE2E
2763+
* @description
2764+
* This method can be used to change which mocked responses `$httpBackend` returns, when defining
2765+
* them with {@link ngMock.$httpBackend#when $httpBackend.when()} (and shortcut methods).
2766+
* By default, `$httpBackend` returns the first definition that matches. When setting
2767+
* `$http.matchLatestDefinition(true)`, it will use the last response that matches, i.e. the
2768+
* one that was added last.
2769+
*
2770+
* ```js
2771+
* hb.when('GET', '/url1').respond(200, 'content', {});
2772+
* hb.when('GET', '/url1').respond(201, 'another', {});
2773+
* hb('GET', '/url1'); // receives "content"
2774+
*
2775+
* $http.matchLatestDefinition(true)
2776+
* hb('GET', '/url1'); // receives "another"
2777+
*
2778+
* hb.when('GET', '/url1').respond(201, 'onemore', {});
2779+
* hb('GET', '/url1'); // receives "onemore"
2780+
* ```
2781+
*
2782+
* This is useful if a you have a default response that is overriden inside specific tests.
2783+
*
2784+
* Note that different from config methods on providers, `matchLatestDefinition()` can be changed
2785+
* even when the application is already running.
2786+
*
2787+
* @param {Boolean=} value value to set, either `true` or `false`. Default is `false`.
2788+
* If omitted, it will return the current value.
2789+
* @return {$httpBackend|Boolean} self when used as a setter, and the current value when used
2790+
* as a getter
2791+
*/
27592792
angular.mock.e2e = {};
27602793
angular.mock.e2e.$httpBackendDecorator =
27612794
['$rootScope', '$timeout', '$delegate', '$browser', createHttpBackendMock];

0 commit comments

Comments
 (0)