Created
June 18, 2014 03:38
-
-
Save miguelmota/84bb25d09dcb20e3ca53 to your computer and use it in GitHub Desktop.
Angular.js $httpBackend example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(module) { | |
module.controller('TestController', ['$scope', '$http', | |
function($scope, $http) { | |
$http.get('/api/stuffs') | |
.then(function(data) { | |
$scope.stuffs = data; | |
}); | |
}]); | |
}(angular.module('testApp'))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('testApp' function () { | |
beforeEach(module('testApp')); | |
describe('testController', function() { | |
var scope, httpBackend, http, controller; | |
beforeEach(inject(function($rootScope, $controller, $httpBackend, $http) { | |
scope = $rootScope.$new(); | |
httpBackend = $httpBackend; | |
http = $http; | |
controller = $controller; | |
httpBackend.when("GET", '/api/stuffs').respond(200, ['a',1,{}]; | |
})); | |
afterEach(function() { | |
httpBackend.verifyNoOutstandingExpectation(); | |
httpBackend.verifyNoOutstandingRequest(); | |
}); | |
it('should GET stuffs', function() { | |
httpBackend.expectGET('/api/stuffs'); | |
controller('TestController', { | |
$scope: scope, | |
$http: http | |
}); | |
httpBackend.flush(); | |
assert(scope.stuffs.length, 3) | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment