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

tryCatchAsync.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
import { delay } from './delay.js'import { tryCatchAsync } from './tryCatchAsync.js'
test('when fallback is function', async () => { const fn = async x => x.x
const result = await tryCatchAsync(fn, () => 1)(null) expect(result).toBe(1)})
test('when fallback throws', async () => { const fn = async x => x.x const fallback = async (err, xx) => xx.y
const result = await tryCatchAsync(fn, fallback)(null) expect(result.message).toMatchInlineSnapshot('undefined')})
test('fallback is not used', async () => { const fn = async x => x.x
expect(tryCatchAsync(fn, false)({ x : 1 })).resolves.toBe(1)})
test('fallback receives error object and all initial inputs', async () => { async function thrower( a, b, c ){ void c throw new Error('throwerError') }
function catchFn( e, a, b, c ){ return [ e.message, a, b, c ].join('|') }
const willThrow = tryCatchAsync(thrower, catchFn) const result = await willThrow( 'A', 'B', 'C' ) expect(result).toBe('throwerError|A|B|C')})
test('when async + value fallback', async () => { const fn = async () => { await delay(100)
return JSON.parse('{a:') }
const result = await tryCatchAsync(fn, 'fallback')(100) expect(result).toBe('fallback')})
rambda

Version Info

Tagged at
2 months ago