3

I have an API that responds status 202 with no data, but the response has a header "Location" that points to a URL.

I've looked at the $httpBackend respond(...) documentation and see no mention of how to mock a header in the response.

I've taken a guess that it might be something like this:

var expectedUrl = 'http://...';
var responseConfig = {
    headers: {
        location: 'http://...'
    }
};
$httpBackend.when(expectedUrl).respond(202, '', responseConfig);

In my unit tests, I'm getting expected status 202, but the headers('location') is returning undefined.

Suggestions?

ngDeveloper
  • 1,304
  • 2
  • 16
  • 34

1 Answers1

5

Ugh, nevermind, found it...

$httpBackend.when(expectedUrl).respond(202, '', responseConfig.headers);

The third parameter is expected as headers and not config.

ngDeveloper
  • 1,304
  • 2
  • 16
  • 34