forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandThen.js
52 lines (43 loc) · 1.21 KB
/
andThen.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var assert = require('assert');
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('andThen', function() {
it('invokes then on the promise with the function passed to it', function(done) {
R.andThen(
function(n) {
eq(n, 1);
done();
},
Promise.resolve(1)
);
});
it('flattens promise returning functions', function(done) {
var incAndWrap = R.compose(Promise.resolve.bind(Promise), R.inc);
var asyncAddThree = R.pipe(incAndWrap, R.andThen(incAndWrap), R.andThen(incAndWrap));
R.andThen(function(result) {
eq(result, 4);
done();
})(asyncAddThree(1));
});
it('throws a typeError if the then method does not exist', function() {
assert.throws(
function() { R.andThen(R.inc, 1); },
function(err) {
return err.constructor === TypeError &&
err.message === '`andThen` expected a Promise, received 1';
}
);
});
it('is not dependent on a particular promise implementation', function(done) {
var thennable = {
then: function(f) {
return f(42);
}
};
var f = function(n) {
eq(n, 42);
done();
};
R.andThen(f, thennable);
});
});