-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprottle.test.js
78 lines (67 loc) · 1.68 KB
/
prottle.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require('chai')
.use(require('chai-as-promised'))
.should();
describe('prottle.js', () => {
let prottle;
beforeEach(() => {
prottle = require('./prottle.js');
});
it('rejects with limit error', () => {
return prottle()
.catch((err) => {
err.message.should.equal('Limit must be at least 1');
});
});
it('rejects with limit error', () => {
return prottle(0)
.catch((err) => {
err.message.should.equal('Limit must be at least 1');
});
});
it('rejects with limit error', () => {
return prottle('dsad')
.catch((err) => {
err.message.should.equal('Limit must be at least 1');
});
});
it('rejects with array error', () => {
return prottle(1, 'boo')
.catch((err) => {
err.message.should.equal('Array of promises required');
});
});
it('does not modify given array', () => {
const arr = [
() => Promise.resolve(1),
() => Promise.resolve(2),
() => Promise.resolve(3)
];
let length = arr.length;
return prottle(1, arr)
.then(() => {
arr.length.should.equal(length);
});
});
it('resolves', () => {
return prottle(3, [
() => Promise.resolve(1),
() => Promise.resolve(2),
() => Promise.resolve(3),
() => Promise.resolve(4),
() => Promise.resolve(5)
])
.should.eventually.eql([
1, 2, 3, 4, 5
]);
});
it('rejects', () => {
return prottle(2, [
() => Promise.resolve(1),
() => Promise.resolve(2),
() => Promise.resolve(3),
() => Promise.reject('beep boop'),
() => Promise.resolve(5)
])
.should.be.rejectedWith('beep boop');
});
});