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.
- Host: GitHub
- URL: https://github.com/normandy72/testing-http
- Owner: Normandy72
- Created: 2023-01-26T11:19:06.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-26T11:44:07.000Z (over 2 years ago)
- Last Synced: 2025-02-11T09:42:35.120Z (3 months ago)
- Topics: angular, angularjs, html, html5, jasmine, jasmine-tests, javascript, js, testing
- Language: JavaScript
- Homepage:
- Size: 125 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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();
});
```