-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
62 lines (52 loc) · 1.07 KB
/
test.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
53
54
55
56
57
58
59
60
61
62
const compose = require('.');
const add = x => y => x + y;
const sqr = x => x ** 2;
const add1 = add(1);
const add2 = add(2);
test('should compose functions', () => {
const testFunction = compose(
sqr,
add2
);
expect(testFunction(2)).toBe(16);
});
test("should error when a function isn't passed", () => {
const testFunction = compose(
sqr,
new Date(),
add2
);
expect(() => testFunction(2)).toThrow();
});
test('should work with different combinations', () => {
expect(
compose(
sqr,
add1
)(2)
).toBe(sqr(add1(2)));
expect(sqr(add1(2))).toBe(9);
expect(
compose(
sqr,
add1
)(2)
).toBe(9);
});
test('should be able to use function multiple times', () => {
const testFunction = compose(
sqr,
add2
);
expect(testFunction(2)).toBe(16);
expect(testFunction(2)).toBe(16);
});
test('should allow multiple args to first functions', () => {
const testFunction = compose(
sqr,
add2,
(x, y) => x * y
);
expect(testFunction(2, 4)).toBe(100);
expect(testFunction(2, 7)).toBe(256);
});