Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

docs(ngMockE2E): add docs for $httpBackend.matchLatestDefinitionEnabl… #16577

Merged
merged 1 commit into from
May 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2756,6 +2756,39 @@ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
* control how a matched request is handled. You can save this object for later use and invoke
* `respond` or `passThrough` again in order to change how a matched request is handled.
*/
/**
* @ngdoc method
* @name $httpBackend#matchLatestDefinition
* @module ngMockE2E
* @description
* This method can be used to change which mocked responses `$httpBackend` returns, when defining
* them with {@link ngMock.$httpBackend#when $httpBackend.when()} (and shortcut methods).
* By default, `$httpBackend` returns the first definition that matches. When setting
* `$http.matchLatestDefinition(true)`, it will use the last response that matches, i.e. the
* one that was added last.
*
* ```js
* hb.when('GET', '/url1').respond(200, 'content', {});
* hb.when('GET', '/url1').respond(201, 'another', {});
* hb('GET', '/url1'); // receives "content"
*
* $http.matchLatestDefinition(true)
* hb('GET', '/url1'); // receives "another"
*
* hb.when('GET', '/url1').respond(201, 'onemore', {});
* hb('GET', '/url1'); // receives "onemore"
* ```
*
* This is useful if a you have a default response that is overriden inside specific tests.
*
* Note that different from config methods on providers, `matchLatestDefinition()` can be changed
* even when the application is already running.
*
* @param {Boolean=} value value to set, either `true` or `false`. Default is `false`.
* If omitted, it will return the current value.
* @return {$httpBackend|Boolean} self when used as a setter, and the current value when used
* as a getter
*/
angular.mock.e2e = {};
angular.mock.e2e.$httpBackendDecorator =
['$rootScope', '$timeout', '$delegate', '$browser', createHttpBackendMock];
Expand Down