Skip to content Skip to sidebar Skip to footer

Angularjs Jasmine Unit Test Fails With Unexpected Request

Following is my myService.spec.js : 'use strict'; describe('myService', function () { var dependentService,dependentService1,rootScope,$q; beforeEach(module('myModu

Solution 1:

Do you have a default route with a templateURL in your application routing? You are probably running into this issue: https://github.com/angular/angular.js/issues/2717

The workaround (which is annoying) is to put an expectGET for the templateURL in your beforeEach and then flush it.

$httpBackend.expectGET('path/to/template/defaulttemplate.html').respond(200, '');
$httpBackend.flush();

You can do it anywhere in there - I try and keep it at the top or bottom so it is obvious that is a workaround and not part of the testing code. Note you will have to put those lines in EVERY test file since the routing is part of app (not the module under test).

Post a Comment for "Angularjs Jasmine Unit Test Fails With Unexpected Request"