Add tests for abort functionality.

This commit is contained in:
Bryce Gibson 2017-02-12 16:38:45 +11:00
parent 9558c8e2e9
commit 6a617aeb87
2 changed files with 38 additions and 4 deletions

View file

@ -390,6 +390,22 @@ o.spec("xhr", function() {
o(xhr.getRequestHeader("Accept")).equals("application/json, text/*")
}
})
o("doesn't fail on abort", function(done) {
var s = new Date
mock.$defineRoutes({
"GET /item": function() {
return {status: 200, responseText: JSON.stringify({a: 1})}
}
})
var failed = false
xhr({method: "GET", url: "/item", config: function (xhr) { setTimeout(function() { xhr.abort() }, 0) }}).catch(function() {
failed = true
}).then(function() {
o(failed).equals(false)
}).then(function() {
done()
})
})
/*o("data maintains after interpolate", function() {
mock.$defineRoutes({
"PUT /items/:x": function() {
@ -463,5 +479,15 @@ o.spec("xhr", function() {
})
})
})
o("rejects on cors-like error", function(done) {
mock.$defineRoutes({
"GET /item": function(request) {
return {status: 0}
}
})
xhr({method: "GET", url: "/item"}).catch(function(e) {
o(e instanceof Error).equals(true)
}).then(done)
})
})
})