forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotherwise.js
36 lines (30 loc) · 919 Bytes
/
otherwise.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var assert = require('assert');
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('otherwise', function() {
it('catches failed promises', function(done) {
R.otherwise(
function(n) {
eq(n, 1);
done();
},
Promise.reject(1)
);
});
it('does nothing to successfully resolved promises', function(done) {
var asyncAddTwo = R.pipe(Promise.resolve.bind(Promise), R.andThen(R.inc), R.otherwise(R.multiply(0)), R.andThen(R.inc));
R.andThen(function(result) {
eq(result, 3);
done();
})(asyncAddTwo(1));
});
it('throws a typeError if the then method does not exist', function() {
assert.throws(
function() { R.otherwise(R.inc, 1); },
function(err) {
return err.constructor === TypeError &&
err.message === '`otherwise` expected a Promise, received 1';
}
);
});
});