-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.js
37 lines (30 loc) · 751 Bytes
/
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
import test from 'ava';
import delay from 'delay';
import pReduce from './index.js';
test('main', async t => {
const fixture = [
Promise.resolve(3),
delay(50, {value: 2}),
5
];
t.is(await pReduce(fixture, async (a, b) => a + b, 0), 10);
});
test('rejects', async t => {
const fixture = [
Promise.resolve(3),
delay.reject(50, {value: new Error('foo')})
];
await t.throwsAsync(pReduce(fixture, (a, b) => a + b, 0), {message: 'foo'});
});
test('reducer throws', async t => {
const fixture = [
Promise.resolve(3),
Promise.resolve(3)
];
await t.throwsAsync(pReduce(fixture, () => {
throw new Error('foo');
}), {message: 'foo'});
});
test('handles empty iterable', async t => {
t.is(await pReduce([], () => {}, 0), 0);
});