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

Add accept json header as default header #27

Merged
merged 1 commit into from Feb 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/prepare.js
Expand Up @@ -10,7 +10,9 @@ var DEFAULTS = {
basePath : '',
body : undefined,
params : undefined,
headers : {},
headers : {
'Accept': 'application/json'
},
method : 'GET',
path : '',
query : {},
Expand Down
9 changes: 9 additions & 0 deletions test/ajax.test.js
Expand Up @@ -31,6 +31,15 @@ describe('ajax', function() {
})
})

it ('automatically adds an Accept JSON header', function (done) {
ajax({
beforeSend(ajax) {
assert.equal(ajax.header.accept, 'application/json')
done()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't asynchronous, but I like to use done any time I'm testing parameters that will be called by a function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise you don't really know if beforeSend was called.

}
})
})

it ('can be mocked out', function(done) {
ajax({
baseURL : 'http://fizbuzz',
Expand Down