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

tryCatch-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
import {tryCatch, delay} from 'rambda'
describe('R.tryCatch', () => { it('synchronous', () => { const fn = (x: any) => x.x === 1
const result = tryCatch(fn, false)(null) result // $ExpectType boolean }) it('synchronous + fallback is function', () => { const fn = (x: any) => typeof x.x const fallback = (x: any) => typeof x const result = tryCatch<any, string>(fn, fallback)(null) result // $ExpectType string })
it('asynchronous', async() => { const fn = async(input: any) => { return typeof JSON.parse('{a:') } const result = await tryCatch<string>(fn, 'fallback')(100) result // $ExpectType string })
it('asynchronous + fallback is asynchronous', async() => { const fn = async(input: any) => { await delay(100) return JSON.parse(`{a:${input}`) } const fallback = async(input: any) => { await delay(100) return 'foo' } const result = await tryCatch<string>(fn, fallback)(100) result // $ExpectType string })})
rambda

Version Info

Tagged at
2 months ago