From bba609d0f25f9d046c53c58d75d0ee5125424d7d Mon Sep 17 00:00:00 2001 From: Schabse Laks Date: Thu, 9 May 2013 11:07:56 -0400 Subject: [PATCH] Fix duplicate promise rejections. We can just reuse chained dispatched rejected promises. The test was also broken; it needs to check for emptiness after fail() runs. Fixes #238. --- CHANGES.md | 1 + q.js | 2 +- spec/q-spec.js | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cc7ce14b..700b1350 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ - `isPromise` and `isPromiseAlike` now always returns a boolean (even for falsy values). #284 @lfac-pt - Support for ES6 Generators in `async` #288 @andywingo + - Clear duplicate promise rejections from dispatch methods #238 @SLaks ## 0.9.3 diff --git a/q.js b/q.js index ad39a899..01fff67f 100644 --- a/q.js +++ b/q.js @@ -791,7 +791,7 @@ function reject(reason) { return rejected ? rejected(reason) : this; } }, function fallback() { - return reject(reason); + return this; }, function valueOf() { return this; }, reason, true); diff --git a/spec/q-spec.js b/spec/q-spec.js index a6e584ac..3369df3b 100644 --- a/spec/q-spec.js +++ b/spec/q-spec.js @@ -2423,10 +2423,10 @@ describe("unhandled rejection reporting", function () { }); it("doesn't report when you chain off a rejection", function () { - Q.reject("this will be handled").get("property").fail(function () { + return Q.reject("this will be handled").get("property").fail(function () { // now it should be handled. + }).fin(function() { + expect(Q.unhandledReasons.length).toEqual(0); }); - - expect(Q.unhandledReasons.length).toEqual(0); }); });