-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathletsdothis.test.js
More file actions
84 lines (73 loc) · 2.12 KB
/
letsdothis.test.js
File metadata and controls
84 lines (73 loc) · 2.12 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const expect = require('expect');
const letsdothis = require('./letsdothis');
let addOne = ((a) => {
return new Promise((resolve, reject) => {
try {
return resolve(a + 1);
}
catch (e) {
return reject();
}
});
});
let addOneDelay = ((a) => {
return new Promise((resolve, reject) => {
try {
return setTimeout(function () { resolve(a + 1) }, 100);
}
catch (e) {
return reject();
}
});
});
let delay = (t) => {
return new Promise(function (resolve) {
setTimeout(function () { resolve() }, 3000);
});
};
describe('Adding Numbers', () => {
it('should return 5 when input is 1 and chained Math.max first.', () => {
let f = letsdothis(Math.max, addOne, addOne, addOne, addOne);
f(1)
.then((result) => {
expect(result).toBe(5);
})
});
it('should return 4 when input is 1 and chained Math.max twice with addOne and addOneDelay.', (done) => {
let f = letsdothis(Math.max, addOneDelay, addOne, Math.max, addOneDelay);
f(1)
.then((result) => {
expect(result).toBe(4);
done();
})
});
it('should return 5 when input is 0 and chained 5 additions.', () => {
let f = letsdothis(addOne, addOne, addOne, addOne, addOne);
f(0)
.then((result) => {
expect(result).toBe(5);
})
});
it('should return 1 when input is 0 and chained 1 additions.', () => {
let f = letsdothis(addOne);
f(0)
.then((result) => {
expect(result).toBe(1);
})
});
it('should return 0 when input is 0 and no functions chained.', () => {
let f = letsdothis();
f(0)
.then((result) => {
expect(result).toBe(0);
})
});
it('should return 5 after chained delay.', (done) => {
let f = letsdothis(addOneDelay, addOneDelay, addOneDelay, addOneDelay, addOneDelay);
f(0)
.then((result) => {
expect(result).toBe(5);
done();
})
});
});