deno.land / x / rambda@v9.1.1 / source / mapAsync.spec.js

mapAsync.spec.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
import { composeAsync } from './composeAsync.js'import { delay } from './delay.js'import { map } from './map.js'import { mapAsync } from './mapAsync.js'
const rejectDelay = a => new Promise((_, reject) => { setTimeout(() => { reject(a + 20) }, 100) })
test('happy', async () => { const fn = async (x, prop) => { await delay(100) expect(prop).toBeNumber()
return x + 1 } const result = await mapAsync(fn, [ 1, 2, 3 ]) expect(result).toEqual([ 2, 3, 4 ])})
test('with object', async () => { const fn = async (x, prop) => { expect(prop).toBeString()
return x + 1 } const result = await mapAsync(fn, { a : 1, b : 2, }) expect(result).toEqual({ a : 2, b : 3, })})
test('with R.composeAsync', async () => { const result = await composeAsync( map(x => x + 1), mapAsync(async x => { delay(x)
return x }), map(x => x * 10) )([ 1, 2, 3 ]) expect(result).toEqual([ 11, 21, 31 ])})
test('error', async () => { try { await mapAsync(rejectDelay)([ 1, 2, 3 ]) } catch (err){ expect(err).toBe(21) }})
rambda

Version Info

Tagged at
2 months ago