Skip to content

Commit

Permalink
Merge pull request #142 from naugtur/fix-json-false
Browse files Browse the repository at this point in the history
fix #141 - json set to false should mean no json
  • Loading branch information
naugtur committed Nov 23, 2016
2 parents dff62ed + 52bb878 commit c5b4619
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -158,7 +158,7 @@ function _createXHR(options) {
var isJson = false
var timeoutTimer

if ("json" in options) {
if ("json" in options && options.json !== false) {
isJson = true
headers["accept"] || headers["Accept"] || (headers["Accept"] = "application/json") //Don't override existing accept header declared by user
if (method !== "GET" && method !== "HEAD") {
Expand Down
11 changes: 11 additions & 0 deletions test/index.js
Expand Up @@ -203,6 +203,17 @@ test("[func] sends options.body as json body when options.json === true", functi
})
})

test("[func] doesn't freak out when json option is false", function(assert) {
xhr.post("/mock/echo", {
json: false,
body: "{\"a\":1}"
}, function(err, resp, body) {
assert.notEqual(resp.rawRequest.headers["Content-Type"], "application/json")
assert.equal(body, "{\"a\":1}")
assert.end()
})
})

test("[func] sends options.json as body when it's not a boolean", function(assert) {
xhr.post("/mock/echo", {
json: {
Expand Down

0 comments on commit c5b4619

Please sign in to comment.