Last active
December 15, 2015 21:26
-
-
Save avington/141fd53bee1ec7c47083 to your computer and use it in GitHub Desktop.
$httpBackend example without the flush command to demonstrate pending requests.
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('SERVICE: imageService', function () { | |
var imageService; | |
var $httpBackend; | |
beforeEach(function () { | |
angular.mock.module('home'); | |
inject(function (_imageService_, _$httpBackend_) { | |
imageService = _imageService_; | |
$httpBackend = _$httpBackend_; | |
}); | |
}); | |
afterEach(function () { | |
$httpBackend.verifyNoOutstandingExpectation(); | |
$httpBackend.verifyNoOutstandingRequest() | |
}); | |
it('should have an existing service called imageService', function () { | |
expect(imageService).toBeDefined(); | |
}); | |
it('should have a function called getImages', function () { | |
expect(angular.isFunction(imageService.getImages)).toBeTruthy(); | |
}); | |
it('should make a get call to images and return a list of images', function () { | |
var data; | |
$httpBackend | |
.when('GET', 'http://localhost:8001/api/homeimages') | |
.respond(200, homeImages); | |
imageService.getImages() | |
.then(function (response) { | |
console.log(response); | |
data = response.data | |
}); | |
expect(data[0].id).toBe(1); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment