@@ -804,6 +804,89 @@ Describe Async.Promise
804
804
endif
805
805
End
806
806
End
807
+
808
+ Describe .on_unhandled_rejection
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
815
+ let l = l:
816
+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
817
+
818
+ let p = P.resolve().then({ -> execute('throw "error"') })
819
+ call s:wait_has_key(l, 'result')
820
+ Assert HasKey(result, 'exception')
821
+ Assert HasKey(result, 'throwpoint')
822
+ End
823
+
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
+
834
+ It should call when promise does not catch with finally
835
+ let l = l:
836
+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
837
+
838
+ let p = P.resolve().then({ -> execute('throw "error"') }).finally({ -> {} })
839
+ call s:wait_has_key(l, 'result')
840
+ Assert HasKey(result, 'exception')
841
+ Assert HasKey(result, 'throwpoint')
842
+ End
843
+
844
+ It should call when promise does not catch with children
845
+ let l = l:
846
+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
847
+
848
+ let p = P.resolve().then({ -> execute('throw "error"') }).then({ -> {} })
849
+ call s:wait_has_key(l, 'result')
850
+ Assert HasKey(result, 'exception')
851
+ Assert HasKey(result, 'throwpoint')
852
+ End
853
+
854
+ It should call when promise does not catch with wait
855
+ let l = l:
856
+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
857
+
858
+ let p = P.resolve().then({ -> execute('throw "error"') }).then({ -> {} })
859
+ let [_, error] = P.wait(p)
860
+ Assert Equals(error, result)
861
+ End
862
+
863
+ It should not call when catched rejected promise
864
+ let l = l:
865
+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
866
+
867
+ let p = P.reject({ 'error': 'error' }).catch({ -> {} })
868
+ call P.wait(Wait(100))
869
+ Assert KeyNotExists(l, 'result')
870
+ End
871
+
872
+ It should not call when catched thrown error
873
+ let l = l:
874
+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
875
+
876
+ let p = P.resolve().then({ -> execute('throw "error"') }).catch({ -> {} })
877
+ call P.wait(Wait(100))
878
+ Assert KeyNotExists(l, 'result')
879
+ End
880
+
881
+ It should not call when promise does not throw error
882
+ let l = l:
883
+ call P.on_unhandled_rejection({ result -> extend(l, { 'result': result }) })
884
+
885
+ let p = P.resolve().then({ -> { 'success': 'success' } })
886
+ call P.wait(Wait(100))
887
+ Assert KeyNotExists(l, 'result')
888
+ End
889
+ End
807
890
End
808
891
809
892
" vim:et ts=2 sts=2 sw=2 tw=0:
0 commit comments