diff --git a/q.js b/q.js index 6e467958..e2f09093 100644 --- a/q.js +++ b/q.js @@ -1118,6 +1118,12 @@ Q.getUnhandledReasons = function () { return unhandledReasons.slice(); }; +Q.getUnhandledRejectionValues = function () { + return array_map(unhandledRejections, function(rejectedPromise) { + return rejectedPromise.exception; + }); +}; + Q.stopUnhandledRejectionTracking = function () { resetUnhandledRejections(); trackUnhandledRejections = false; diff --git a/spec/q-spec.js b/spec/q-spec.js index 6d4068b5..383e04e7 100644 --- a/spec/q-spec.js +++ b/spec/q-spec.js @@ -2976,4 +2976,21 @@ describe("unhandled rejection reporting", function () { expect(Q.getUnhandledReasons()).toEqual([]); }); + + describe("getUnhandledRejectionValues", function () { + it("contains a reference to the rejection value", function () { + var rejectionRef = { some: "reason" }; + Q.reject(rejectionRef); + + expect(Q.getUnhandledRejectionValues()).toEqual([rejectionRef]); + }); + + it("resets after calling `Q.resetUnhandledRejections`", function () { + Q.reject("a reason"); + + Q.resetUnhandledRejections(); + expect(Q.getUnhandledRejectionValues()).toEqual([]); + }); + }); + });