Angular Jasmine $location $httpBackend: "Error: unexpected request" <p>I'm trying to unit test $urlRouterProvider.otherwise to show the url as whatever the user entered. However, every time I use $location in my unit test, I get this error</p> <pre><code>path default rerouting should go to error upon bad rerouting url FAILED Error: Unexpected request: GET public/templates/404.html No more request expected at $httpBackend (/Users/project/lib/angular-mocks.js:1207:9) </code></pre> <p>This is what I have in my config file:</p> <pre><code>$urlRouterProvider .when('', '/main') .when('/', '/main') .otherwise(function($injector){ $injector.get('$state').go('404', {}, { location: false }); }); </code></pre> <p>And this is what I have as my spec.js file</p> <pre><code>describe('path', function(){ var $rootScope, $state, $location, $injector, $templateCache, state; beforeEach(angular.mock.module('app')); beforeEach(angular.mock.inject(function(_$rootScope_, _$state_, _$injector_, _$location_, _$templateCache_, _$httpBackend_){ $rootScope = _$rootScope_; $state = _$state_; $injector = _$injector_; $location = _$location_; $templateCache = _$templateCache_; $httpBackend = _$httpBackend_; $templateCache.put('public/templates/main.html', ''); $templateCache.put('public/template/audio.html', ''); $templateCache.put('public/template/404.html', ''); })); describe('default rerouting', function(){ it('should go to error upon bad url', function(){ var badUrl = '/badUrlToTest'; goTo(badUrl); expect($state.current.name).toEqual('404'); expect($location.url()).toBe(badUrl); }); }); function goTo(url){ $location.url(url); $rootScope.$digest(); } }) </code></pre> <p>Using $state works just fine, and in the <code>goTo()</code> function $location seems to work, so why does using <code>$location.url()</code> (or <code>$location.path</code>) throw an error asking about $httpBackend when I'm not using an <code>$http.get()</code> request?</p>