From 1c504f0d799a4de24e8b38a7319e23abe382cad7 Mon Sep 17 00:00:00 2001 From: Brian Cavalier Date: Sun, 25 May 2014 14:39:19 -0400 Subject: [PATCH] Remove commented-out code. Improve fold tests. Rebuild es6-shim. Update changelog --- CHANGES.md | 5 +++++ es6-shim/Promise.js | 7 ------ lib/makePromise.js | 7 ------ test/fold-test.js | 53 ++++++++++++++++++++++++++++++++------------- 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 115f9169..9caefe6d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +### 3.2.2 + +* More mem and perf improvements +* Improvements to unhandled rejection reporting + ### 3.2.1 * Minor mem and perf tweaks for `when.all` diff --git a/es6-shim/Promise.js b/es6-shim/Promise.js index 59d54bc9..02efa12e 100644 --- a/es6-shim/Promise.js +++ b/es6-shim/Promise.js @@ -600,13 +600,6 @@ define(function() { return h; }; -// function join(h) { -// while(h.handler !== void 0) { -// h = h.handler; -// } -// return h; -// } -// Handler.prototype.chain = function(to, fulfilled, rejected, progress) { this.when({ resolve: noop, diff --git a/lib/makePromise.js b/lib/makePromise.js index d48be3ad..51e5b0c4 100644 --- a/lib/makePromise.js +++ b/lib/makePromise.js @@ -359,13 +359,6 @@ define(function() { return h; }; -// function join(h) { -// while(h.handler !== void 0) { -// h = h.handler; -// } -// return h; -// } -// Handler.prototype.chain = function(to, fulfilled, rejected, progress) { this.when({ resolve: noop, diff --git a/test/fold-test.js b/test/fold-test.js index 17d895bf..70b91e38 100644 --- a/test/fold-test.js +++ b/test/fold-test.js @@ -1,32 +1,55 @@ var buster = typeof window !== 'undefined' ? window.buster : require('buster'); var assert = buster.assert; var when = require('../when'); +var sentinel = { value: 'sentinel' }; +var other = { value: 'other' }; -function sum(x, y) { - return x + y; -} - -function equal(x, y) { - if (x !== y) { throw 'not equal!'; } -} +function noop() {} buster.testCase('promise.fold', { + 'should pass value and arg': function() { + return when.resolve(other).fold(function(a, b) { + assert.same(a, sentinel); + assert.same(b, other); + }, sentinel); + }, + 'should pairwise combine two promises': function() { - return when.resolve(1).fold(sum, when.resolve(2)).then(function(res){ - assert.equals(res, 3); + return when.resolve(1).fold(function sum(x, y) { + return x + y; + }, when.resolve(2)).then(function(x){ + assert.equals(x, 3); }); }, - 'should still fail normally after a fold': function() { - return when.resolve(1).fold(equal, 2)['catch'](function(res){ - assert.equals(res, 'not equal!'); + 'should reject if combine throws': function() { + return when.resolve(1).fold(function() { + throw sentinel; + }, 2)['catch'](function(e){ + assert.same(e, sentinel); }); }, - 'should reject and not call fold if previous promise rejects': function() { - return when.reject(1).fold(equal, 2)['catch'](function(res){ - assert.equals(res, 1); + + 'should reject if combine returns rejection': function() { + return when.resolve(1).fold(when.reject, sentinel)['catch'](function(e){ + assert.same(e, sentinel); }); + }, + + 'should reject and not call combine': { + 'if promise rejects': function() { + return when.reject(sentinel).fold(noop, 2)['catch'](function(e){ + assert.same(e, sentinel); + }); + }, + + 'if arg rejects': function() { + return when.resolve(1).fold(noop, when.reject(sentinel)) + ['catch'](function(e){ + assert.same(e, sentinel); + }); + } } });