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

ifElseAsync-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
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
import {ifElseAsync, delay} from 'rambda'
describe('R.ifElseAsync', () => { it('arity of 1 - condition is async', async() => { const condition = async(x: number) => { await delay(100)
return x > 4 } const whenTrue = (x: number) => `foo${x}` const whenFalse = (x: number) => `bar${x}` const fn = ifElseAsync(condition, whenTrue, whenFalse) fn // $ExpectType (x: number) => Promise<string>
const result = await fn(5) result // $ExpectType string })
it('arity of 1 - condition is sync', async() => { const condition = (x: number) => x > 4 const whenTrue = async(x: number) => { await delay(100) return `foo${x}` } const whenFalse = async(x: number) => { await delay(100) return `bar${x}` } const fn = ifElseAsync(condition, whenTrue, whenFalse) fn // $ExpectType (x: number) => Promise<string>
const result = await fn(5) result // $ExpectType string })
it('arity of 1 - all inputs are async', async() => { const condition = async(x: number) => { await delay(100)
return x > 4 } const whenTrue = async(x: number) => { await delay(100) return `foo${x}` } const whenFalse = async(x: number) => { await delay(100) return `bar${x}` } const fn = ifElseAsync(condition, whenTrue, whenFalse) fn // $ExpectType (x: number) => Promise<Promise<string>>
const result = await fn(5) result // $ExpectType string })
it('arity of 2 - condition is async', async() => { const condition = async(x: number, y: string) => { await delay(100)
return x + y.length > 4 } const whenTrue = (x: number, y: string) => `foo${x}${y}` const whenFalse = (x: number, y: string) => `bar${x}${y}` const fn = ifElseAsync(condition, whenTrue, whenFalse) fn // $ExpectType (x: number, y: string) => Promise<string>
const result = await fn(5, 'foo') result // $ExpectType string })
it('arity of 2 - condition is sync', async() => { const condition = (x: number, y: string) => x + y.length > 4 const whenTrue = async(x: number, y: string) => { await delay(100) return `foo${x}${y}` } const whenFalse = async(x: number, y: string) => { await delay(100) return `bar${x}${y}` } const fn = ifElseAsync(condition, whenTrue, whenFalse) fn // $ExpectType (x: number, y: string) => Promise<string>
const result = await fn(5, 'foo') result // $ExpectType string })
it('arity of 2 - all inputs are async', async() => { const condition = async(x: number, y: string) => { await delay(100)
return x + y.length > 4 } const whenTrue = async(x: number, y: string) => { await delay(100) return `foo${x}${y}` } const whenFalse = async(x: number, y: string) => { await delay(100) return `bar${x}${y}` } const fn = ifElseAsync(condition, whenTrue, whenFalse) fn // $ExpectType (x: number, y: string) => Promise<Promise<string>>
const result = await fn(5, 'foo') result // $ExpectType string })})
rambda

Version Info

Tagged at
2 months ago