0

I am using karma to test a controller in my angular app, the app it self works as expected but unit test throws error: unexpected request: GET views/home.html as I got the problem is by ui-router and $httpBackend. so one approach was caching by ‘karma-preprocessor’ but what I have done is:

var MenuController, scope, $httpBackend;
// Initialize the controller and a mock scope
beforeEach(inject(function($controller, _$httpBackend_, $rootScope, menuService) {
// place here mocked dependencies
$httpBackend = _$httpBackend_;
$httpBackend.whenGET("views/header.html").respond(200,'');
$httpBackend.expectGET("http://localhost:3000/dishes").respond([{ ....

but the GET error shows for every template in my views folder.

NOW is there any way to ignore all templates and any other unexpected GET requests?

Amir-Mousavi
  • 4,273
  • 12
  • 70
  • 123

1 Answers1

1

You can create a regular expression that matches all the templates requests: httpBackend.whenGET(/views\/.*\.html/).respond(200, {}); or only httpBackend.whenGET(/views\//).respond(200, {})

rave
  • 1,022
  • 1
  • 12
  • 23