Rewrite: ignore m.request deserialize option if extract is passed

This commit is contained in:
Patrik Johnson 2016-08-04 19:19:12 +03:00
parent 0d1c1a3f16
commit 88e7cf5454
4 changed files with 43 additions and 4 deletions

View file

@ -38,7 +38,7 @@ module.exports = function($window) {
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
try {
var response = args.deserialize(args.extract(xhr, args))
var response = (args.extract !== extract) ? args.extract(xhr, args) : args.deserialize(args.extract(xhr, args))
if (xhr.status >= 200 && xhr.status < 300) {
stream(cast(args.type, response))
}

View file

@ -210,7 +210,7 @@ o.spec("xhr", function() {
}
})
xhr({method: "GET", url: "/item", extract: extract}).map(function(data) {
o(data).deepEquals({test: 123})
o(data).equals("{\"test\":123}")
}).map(done)
})
o("extract parameter works in POST", function(done) {
@ -224,7 +224,24 @@ o.spec("xhr", function() {
}
})
xhr({method: "POST", url: "/item", extract: extract}).map(function(data) {
o(data).deepEquals({test: 123})
o(data).equals("{\"test\":123}")
}).map(done)
})
o("ignores deserialize if extract is defined", function(done) {
var extract = function(data) {
return data.status
}
var deserialize = o.spy()
mock.$defineRoutes({
"GET /item": function(request) {
return {status: 200, responseText: ""}
}
})
xhr({method: "GET", url: "/item", extract: extract, deserialize: deserialize}).map(function(data) {
o(data).equals(200)
}).map(function() {
o(deserialize.callCount).equals(0)
}).map(done)
})
o("config parameter works", function(done) {