An open API service indexing awesome lists of open source software.

https://github.com/normandy72/testing-http

Testing AngularJS Services and $http. Coursera course "Single Page Web Applications with AngularJS" by Yaakov Chaikin.
https://github.com/normandy72/testing-http

angular angularjs html html5 jasmine jasmine-tests javascript js testing

Last synced: about 1 month ago
JSON representation

Testing AngularJS Services and $http. Coursera course "Single Page Web Applications with AngularJS" by Yaakov Chaikin.

Awesome Lists containing this project

README

        

# Testing AngularJS Services and $http
### beforeEach Setup
```
var myService;
var $httpBackend;

beforeEach(function(){
module('MyApp');

inject(function($injector){
myService = $injector.get('MyService');
$httpBackend = $injector.get('$httpBackend');
});
});
```
`$injector` - inject the regular Angular $injector to retrieve service.

### Test Method
```
it("should return some data", function(){
// simulate HTTP GET
$httpBackend.whenGet('http://...')
.respond(['val1', 'val2']);

myService.getItems().then(function(response){
expect(response.data).toEqual(['val1', [val2]]);
});

$httpBackend.flush();
});
```