-
Notifications
You must be signed in to change notification settings - Fork 2
/
a_reduce.spec.ts
52 lines (34 loc) · 1.08 KB
/
a_reduce.spec.ts
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
import {aReduce} from '../../src/async';
/**
* tsfun | aReduce
*/
describe('aReduce', () => {
it('array - single parameter list', async done => {
const sum = await aReduce(delayedAdd, 0, [1, 3, 7])
expect(sum).toBe(11)
done()
})
it('array - single parameter list, collection at first position', async done => {
const sum = await aReduce([1, 3, 7], delayedAdd, 0)
expect(sum).toBe(11)
done()
})
it('array - multiple parameter lists', async done => {
const asyncSum = await aReduce(delayedAdd, 0)
const sum = await asyncSum([1, 3, 7])
expect(sum).toBe(11)
done()
})
it('object', async done => {
expect(
await (await aReduce((acc: string, b: string, k: string) => Promise.resolve(acc + b + k), '.'))({
a: '3',
b: '7',
c: '5'
}))
.toBe('.3a7b5c')
done()
})
const delayedAdd =
(acc, val) => new Promise<any>(resolve => setTimeout(() => resolve(acc + val), 150))
})