AngularJS - $httpBackend return 200 with success = false

391 Views Asked by At

I've bumped into some very strange behaviour when trying to mock server-api while performing e2e tests.

Here's my code:

$httpBackend.whenPOST(...).respond(function () {
           return [200, {success:true, errors: []}];
});

This part works fine, but when I turn success = false like so:

$httpBackend.whenPOST(...).respond(function () {
           return [200, {success:false, errors: [ { ... } ]}];
});

the response code becomes 500, something I don't want to happen.

Interestingly, when I change the key 'success' to something else (like 'sukcess'), the response code remains 200 and everything works as expected.

Does $httpBackend look at the json response and alter the response code if it finds the key 'success' equals false in the response data? If so this is very strange behaviour. Has anyone encountered something like this before? And if so, is there anything I can do to avoid this behaviour other than changing the word 'success' in all of my json responses?

0

There are 0 best solutions below