Is It Possible To Set A Wildcard For $httpBackend Responses?
Suppose I have the following test code in AngularJS: var someURL; var dummyJSON; $httpBackend.whenGET(someURL).respond(dummyJSON); Is there a way of making this the response for a
Solution 1:
I've had luck with expressions like whenGET(/^\/api\//) – which means starts with /api/. In the regex, ^ will match the start of the string and \/ will match a literal / in the URL.
If that doesn't match your requests, try whenGET(/\/api\//) which should match absolute URLs as well as relative URLs.
Solution 2:
You can also use a function if you don't want to deal with regex. Something like:
$httpBackend.when("GET", function(url) {return url.indexOf("/api/") === 0;}
Post a Comment for "Is It Possible To Set A Wildcard For $httpBackend Responses?"