Skip to content

Instantly share code, notes, and snippets.

@pirey
Last active December 30, 2016 08:03
Show Gist options
  • Save pirey/07fe56bd92a2a371de223006740c6b63 to your computer and use it in GitHub Desktop.
Save pirey/07fe56bd92a2a371de223006740c6b63 to your computer and use it in GitHub Desktop.
solution for $httpBackend unexpected requests in jasmine spec for angularjs project
describe('testing using $httpBackend in ionic app', function() {
var yourAsyncService;
var $httpBackend;
// prepare our service and $httpBackend
beforeEach(function() {
// load module that holds our service
// make sure the required module is loaded
module('module_name');
// this solves unexpected $httpBackend requests issue
// https://github.com/angular-ui/ui-router/issues/212#issuecomment-76230499
module(function($provide, $urlRouterProvider) {
$provide.value('$ionicTemplateCache', function(){} );
$urlRouterProvider.deferIntercept();
});
// get the services
inject(function(_$httpBackend_, _yourAsyncService_) {
yourAsyncService = _yourAsyncService_;
$httpBackend = _$httpBackend_;
});
});
// some $httpBackend convention
afterEach(function() {
$httpBackend.verifyNoOutstandingRequest();
$httpBackend.verifyNoOutstandingExpectation();
});
// your tests here...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment