Skip to content

Commit a946ef5

Browse files
committed
Fix xhr abort test.
Need to be more creative about ensuring that onreadystatechange is called, but that the test conditions execute after that the function (that does nothing...) is called.
1 parent 27881af commit a946ef5

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

request/tests/test-request.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,30 @@ o.spec("xhr", function() {
397397
return {status: 200, responseText: JSON.stringify({a: 1})}
398398
}
399399
})
400+
400401
var failed = false
401-
xhr({method: "GET", url: "/item", config: function (xhr) { setTimeout(function() { xhr.abort() }, 0) }}).catch(function() {
402+
var resolved = false
403+
function handleAbort(xhr) {
404+
var onreadystatechange = xhr.onreadystatechange // probably not set yet
405+
var testonreadystatechange = function() {
406+
onreadystatechange.call(xhr)
407+
setTimeout(function() { // allow promises to (not) resolve first
408+
o(failed).equals(false)
409+
o(resolved).equals(false)
410+
done()
411+
}, 0)
412+
}
413+
Object.defineProperty(xhr, 'onreadystatechange', {
414+
set: function(val) { onreadystatechange = val }
415+
, get: function() { return testonreadystatechange }
416+
})
417+
xhr.abort()
418+
}
419+
xhr({method: "GET", url: "/item", config: handleAbort}).catch(function() {
402420
failed = true
403-
}).then(function() {
404-
o(failed).equals(false)
405-
}).then(function() {
406-
done()
421+
})
422+
.then(function() {
423+
resolved = true
407424
})
408425
})
409426
o("doesn't fail on file:// status 0", function(done) {

0 commit comments

Comments
 (0)