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

Commit ed964c2

Browse files
author
Michael B. Younkin
committed
Update documentation for the mock $httpBackend
The example either does not work with the latest version of angular.js or it is unclear. Many comments on the documentation page for $httpBackend indicate that it is unclear. By looking at other sources I identified the issues and made some changes to make the example code work.
1 parent f810940 commit ed964c2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/ngMock/angular-mocks.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,10 +851,13 @@ angular.mock.dump = function(object) {
851851
}
852852
853853
// testing controller
854-
var $httpBackend;
854+
var $httpBackend,
855+
$http;
855856
856857
beforeEach(inject(function($injector) {
858+
// No configuration necessary; $httpBackend replaces the normal $http backend when the mock library is loaded
857859
$httpBackend = $injector.get('$httpBackend');
860+
$http = $injector.get('$http');
858861
859862
// backend definition common for all tests
860863
$httpBackend.when('GET', '/auth.py').respond({userId: 'userX'}, {'A-Token': 'xxx'});
@@ -869,6 +872,7 @@ angular.mock.dump = function(object) {
869872
870873
it('should fetch authentication token', function() {
871874
$httpBackend.expectGET('/auth.py');
875+
new MyController({}, $http);
872876
var controller = scope.$new(MyController);
873877
$httpBackend.flush();
874878
});

0 commit comments

Comments
 (0)