Skip to content

Instantly share code, notes, and snippets.

@avington
Last active December 15, 2015 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avington/141fd53bee1ec7c47083 to your computer and use it in GitHub Desktop.
Save avington/141fd53bee1ec7c47083 to your computer and use it in GitHub Desktop.
$httpBackend example without the flush command to demonstrate pending requests.
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