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

partialObject.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
import { delay } from './delay.js'import { partialObject } from './partialObject.js'import { type } from './type.js'
test('with plain function', () => { const fn = ({ a, b, c }) => a + b + c const curried = partialObject(fn, { a : 1 })
expect(type(curried)).toBe('Function') expect(curried({ b : 2, c : 3, })).toBe(6)})
test('with function that throws an error', () => { const fn = ({ a, b, c }) => { throw new Error('foo') } const curried = partialObject(fn, { a : 1 })
expect(type(curried)).toBe('Function') expect(() => curried({ b : 2, c : 3, })).toThrowErrorMatchingInlineSnapshot('"foo"')})
test('with async', async () => { const fn = async ({ a, b, c }) => { await delay(100)
return a + b + c }
const curried = partialObject(fn, { a : 1 })
const result = await curried({ b : 2, c : 3, })
expect(result).toBe(6)})
test('async function throwing an error', async () => { const fn = async ({ a, b, c }) => { await delay(100) throw new Error('foo') }
const curried = partialObject(fn, { a : 1 })
try { await curried({ b : 2, c : 3, }) expect(true).toBeFalsy() } catch (e){ expect(e.message).toBe('foo') }})
rambda

Version Info

Tagged at
2 months ago