Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set response headers for mocked ajax requests? #144

Closed
amit1911 opened this issue Jan 12, 2016 · 1 comment
Closed

How to set response headers for mocked ajax requests? #144

amit1911 opened this issue Jan 12, 2016 · 1 comment

Comments

@amit1911
Copy link

I am mocking an ajax request using jasmine-ajax as follows

jasmine.Ajax.requests.mostRecent().respondWith({
    "status": 200,
    "responseText": '{}'
});

I am trying to get the 'Location' header for the request object passed to the ajax success callback as follows:

success(function(data, textStatus, request) {
    var url = request.getResponseHeader('Location');
    url = url.substring(...);
}

but it returns null and the jasmine test fails because substring function is called on null. What should I do? Note: I can access the 'Location' header just fine if the ajax request is not mocked.

@amit1911 amit1911 changed the title How to set headers for mocked ajax requests? How to set response headers for mocked ajax requests? Jan 12, 2016
@slackersoft
Copy link
Member

In your call to respondWith you should be able to provide a responseHeaders key.

I've also created an issue on the docs site jasmine/jasmine.github.io#54 to add this to the existing docs.

Thanks for using Jasmine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants