@@ -806,7 +806,12 @@ Describe Async.Promise
806806 End
807807
808808 Describe .on_unhandled_rejection
809- It should call when promsie does not catch
809+
810+ After each
811+ call P.on_unhandled_rejection(P.noop)
812+ End
813+
814+ It should call when promise throw error but unhandled
810815 let l = l:
811816 call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
812817
@@ -816,6 +821,16 @@ Describe Async.Promise
816821 Assert HasKey(result, 'throwpoint')
817822 End
818823
824+ It should call when promise rejected but unhandled
825+ let l = l:
826+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
827+
828+ let p = P.reject({ 'error': 'error' })
829+ call s:wait_has_key(l, 'result')
830+ Assert HasKey(result, 'error')
831+ Assert Equals(result.error, 'error')
832+ End
833+
819834 It should call when promise does not catch with finally
820835 let l = l:
821836 call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
@@ -853,6 +868,15 @@ Describe Async.Promise
853868 call P.wait(Wait(100))
854869 Assert KeyNotExists(l, 'result')
855870 End
871+
872+ It should not call when promise does not throw error
873+ let l = l:
874+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
875+
876+ let p = P.resolve().then({ -> { 'success': 'success' } })
877+ call P.wait(Wait(100))
878+ Assert KeyNotExists(l, 'result')
879+ End
856880 End
857881End
858882
0 commit comments