mardi 30 août 2016

$httpBackend.expectGET() without URL still captures request

Doing AngularJS unit tests using the $httpBackend service. For some reason $httpBackend.expectGET('') or $httpBackend.expectGET() seem to be working like a catch-all for the request coming from the tested code i.e. Karma says the test passes with SUCCESS.

More precisely, if I mock the backend with:

$httpBackend.expectGET('').respond(200,'all good');

The tested angular code that makes the $http.get('specific/url/here') call will get captured by this empty `$httpBackend.expectGET('').

I know it is this one that catches the request because if I instead mock the backend with:

$httpBackend.expectGET('bad/url/here').respond(200,'all good');

then Karma FAILs with message:

Error: Unexpected request: GET specific/url/here
Expected GET bad/url/here

Is that expected behavior?

I don't see something relevant in the docs.

Aucun commentaire:

Enregistrer un commentaire