Skip to content

Commit

Permalink
Remove commented-out code. Improve fold tests. Rebuild es6-shim. Upda…
Browse files Browse the repository at this point in the history
…te changelog
  • Loading branch information
briancavalier committed May 25, 2014
1 parent 82c246c commit 1c504f0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
7 changes: 0 additions & 7 deletions es6-shim/Promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions lib/makePromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
53 changes: 38 additions & 15 deletions test/fold-test.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
}

});

0 comments on commit 1c504f0

Please sign in to comment.