UNPKG

1.08 kBJavaScriptView Raw
1const assert = require('assert');
2const {compose, pipe} = require('../fp');
3
4const incrementBy = value => data => value + data;
5const foldBy = value => data => value * data;
6const rest = value => data => Promise.resolve(data - value);
7
8describe('FP', function() {
9 describe('#compose()', function() {
10 it('should return a composed function of right to left', function(){
11 let calc = compose(foldBy(2), incrementBy(1));
12 assert.equal(calc(1),4);
13 });
14 it('should return a composed function that works with promises', async function(){
15 let calc = compose(foldBy(2), rest(1), incrementBy(2));
16 assert.equal(await calc(1),4);
17 });
18 });
19 describe('#pipe()', function() {
20 it('should return a composed function from left to right', function(){
21 let calc = pipe(foldBy(2), incrementBy(1));
22 assert.equal(calc(1),3);
23 });
24 it('should return a composed function that works with promises', async function(){
25 let calc = pipe(foldBy(2), rest(1), incrementBy(2));
26 assert.equal(await calc(1),3);
27 });
28 });
29});