AngularJS: $ httpBackend pokes fun at only some requests

I am using the ngMock module to mock multiple requests:

 $httpBackend.whenGET("/accounts").respond([obj]);

      

However, it looks like loading the module expects you to mock ALL requests. So if I make a request other than the ones I mocked, I get an "Unexpected Request" error.

How can I set it up so that it ONLY intercepts the requests I am mocking explicitly and passes everything else through?

+3


source to share


1 answer


You can use regex and passThrough () function built into $ httpBackend.



beforeEach(inject(function($httpBackend){
    $httpBackend.whenGET("/accounts").respond([obj]);
    //Pass everything else through
    $httpBackend.whenGET(/^\w+.*/).passThrough();
}));

      

+1


source







All Articles