Test branched rejection handler resolution

This commit is contained in:
Barney Carroll 2016-12-07 16:14:08 +00:00
parent b4f1f35c54
commit d74fa75832
2 changed files with 42 additions and 1 deletions

View file

@ -403,6 +403,24 @@ o.spec("promise", function() {
done()
})
})
o("triggers all branched rejection handlers upon rejection", function(done) {
var promise = Promise.reject()
var then = o.spy()
var catch1 = o.spy()
var catch2 = o.spy()
var catch3 = o.spy()
promise.catch(catch1)
promise.then(then, catch2).catch(catch3)
promise.then(null, function(){
o(catch1.callCount).equals(1, "first branch catch triggers")
o(then.callCount).equals(0, "second branch then resolution handler doesn't trigger")
o(catch2.callCount).equals(1, "second branch then rejection handler triggers")
o(catch3.callCount).equals(1, "second branch subseqent catch triggers")
done()
})
})
o("does not absorb resolved promise via static rejector", function(done) {
var promise = Promise.reject(Promise.resolve(1))

View file

@ -377,5 +377,28 @@ o.spec("xhr", function() {
o(e.message).equals("error")
}).then(done)
})
o("triggers all branched catches upon rejection", function(done) {
mock.$defineRoutes({
"GET /item": function(request) {
return {status: 500, responseText: "error"}
}
})
var request = xhr({method: "GET", url: "/item"})
var then = o.spy()
var catch1 = o.spy()
var catch2 = o.spy()
var catch3 = o.spy()
request.catch(catch1)
request.then(then, catch2).catch(catch3)
setTimeout(function(){
o(catch1.callCount).equals(1, "first branch catch triggers")
o(then.callCount).equals(0, "second branch then resolution handler doesn't trigger")
o(catch2.callCount).equals(1, "second branch then rejection handler triggers")
o(catch3.callCount).equals(1, "second branch subseqent catch triggers")
done()
}, 10)
})
})
})