@@ -804,6 +804,56 @@ Describe Async.Promise
804804 endif
805805 End
806806 End
807+
808+ Describe .on_unhandled_rejection
809+ It should call when promsie does not catch
810+ let l = l:
811+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
812+
813+ let p = P.resolve().then({ -> execute('throw "error"') })
814+ call s:wait_has_key(l, 'result')
815+ Assert HasKey(result, 'exception')
816+ Assert HasKey(result, 'throwpoint')
817+ End
818+
819+ It should call when promise does not catch with finally
820+ let l = l:
821+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
822+
823+ let p = P.resolve().then({ -> execute('throw "error"') }).finally({ -> {} })
824+ call s:wait_has_key(l, 'result')
825+ Assert HasKey(result, 'exception')
826+ Assert HasKey(result, 'throwpoint')
827+ End
828+
829+ It should call when promise does not catch with children
830+ let l = l:
831+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
832+
833+ let p = P.resolve().then({ -> execute('throw "error"') }).then({ -> {} })
834+ call s:wait_has_key(l, 'result')
835+ Assert HasKey(result, 'exception')
836+ Assert HasKey(result, 'throwpoint')
837+ End
838+
839+ It should call when promise does not catch with wait
840+ let l = l:
841+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
842+
843+ let p = P.resolve().then({ -> execute('throw "error"') }).then({ -> {} })
844+ let [_, error] = P.wait(p)
845+ Assert Equals(error, result)
846+ End
847+
848+ It should not call when promise catched
849+ let l = l:
850+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
851+
852+ let p = P.resolve().then({ -> execute('throw "error"') }).catch({ -> {} })
853+ call P.wait(Wait(100))
854+ Assert KeyNotExists(l, 'result')
855+ End
856+ End
807857End
808858
809859" vim:et ts=2 sts=2 sw=2 tw=0:
0 commit comments