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

ifElseAsync.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { delay } from './delay.js'import { ifElseAsync } from './ifElseAsync.js'
test('arity of 1 - condition is async', async () => { const condition = async x => { await delay(100)
return x > 4 } const whenTrue = x => x + 1 const whenFalse = x => x + 10 const fn = ifElseAsync( condition, whenTrue, whenFalse ) const result = await Promise.all([ fn(5), fn(1) ]) expect(result).toEqual([ 6, 11 ])})
test('arity of 1 - condition is sync', async () => { const condition = x => x > 4 const whenTrue = async x => { await delay(100)
return x + 1 } const whenFalse = async x => { await delay(100)
return x + 10 } const fn = ifElseAsync( condition, whenTrue, whenFalse ) const result = await Promise.all([ fn(5), fn(1) ]) expect(result).toEqual([ 6, 11 ])})
test('arity of 1 - all inputs are async', async () => { const condition = async x => { await delay(100)
return x > 4 } const whenTrue = async x => { await delay(100)
return x + 1 } const whenFalse = async x => { await delay(100)
return x + 10 } const fn = ifElseAsync( condition, whenTrue, whenFalse ) const result = await Promise.all([ fn(5), fn(1) ]) expect(result).toEqual([ 6, 11 ])})
test('arity of 2 - condition is async', async () => { const condition = async (x, y) => { await delay(100)
return x + y > 4 } const whenTrue = (x, y) => x + y + 1 const whenFalse = (x, y) => x + y + 10 const fn = ifElseAsync( condition, whenTrue, whenFalse ) const result = await Promise.all([ fn(14, 20), fn(1, 3) ]) expect(result).toEqual([ 35, 14 ])})
test('arity of 2 - condition is sync', async () => { const condition = (x, y) => x + y > 4 const whenTrue = async (x, y) => { await delay(100)
return x + y + 1 } const whenFalse = async (x, y) => { await delay(100)
return x + y + 10 } const fn = ifElseAsync( condition, whenTrue, whenFalse ) const result = await Promise.all([ fn(14, 20), fn(1, 3) ]) expect(result).toEqual([ 35, 14 ])})
test('arity of 2 - all inputs are async', async () => { const condition = async (x, y) => { await delay(100)
return x + y > 4 } const whenTrue = async (x, y) => { await delay(100)
return x + y + 1 } const whenFalse = async (x, y) => { await delay(100)
return x + y + 10 } const fn = ifElseAsync( condition, whenTrue, whenFalse ) const result = await Promise.all([ fn(14, 20), fn(1, 3) ]) expect(result).toEqual([ 35, 14 ])})
rambda

Version Info

Tagged at
2 months ago