-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove commented-out code. Improve fold tests. Rebuild es6-shim. Upda…
…te changelog
- Loading branch information
1 parent
82c246c
commit 1c504f0
Showing
4 changed files
with
43 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} | ||
|
||
}); |