deno.land / x / rambda@v9.1.1 / source / pick.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
import { pick } from './pick.js'
const obj = { a : 1, b : 2, c : 3,}
test('props to pick is a string', () => { const result = pick('a,c', obj) const resultCurry = pick('a,c')(obj) const expectedResult = { a : 1, c : 3, }
expect(result).toEqual(expectedResult) expect(resultCurry).toEqual(expectedResult)})
test('when prop is missing', () => { const result = pick('a,d,f', obj) expect(result).toEqual({ a : 1 })})
test('with list indexes as props', () => { const list = [ 1, 2, 3 ] const expected = { 0 : 1, 2 : 3, } expect(pick([ 0, 2, 3 ], list)).toEqual(expected) expect(pick('0,2,3', list)).toEqual(expected)})
test('props to pick is an array', () => { expect(pick([ 'a', 'c' ])({ a : 'foo', b : 'bar', c : 'baz', })).toEqual({ a : 'foo', c : 'baz', })
expect(pick([ 'a', 'd', 'e', 'f' ])({ a : 'foo', b : 'bar', c : 'baz', })).toEqual({ a : 'foo' })
expect(pick('a,d,e,f')(null)).toBeUndefined()})
test('works with list as input and number as props - props to pick is an array', () => { const result = pick([ 1, 2 ], [ 'a', 'b', 'c', 'd' ]) expect(result).toEqual({ 1 : 'b', 2 : 'c', })})
test('works with list as input and number as props - props to pick is a string', () => { const result = pick('1,2', [ 'a', 'b', 'c', 'd' ]) expect(result).toEqual({ 1 : 'b', 2 : 'c', })})
test('with symbol', () => { const symbolProp = Symbol('s') expect(pick([ symbolProp ], { [ symbolProp ] : 'a' })).toMatchInlineSnapshot(`{ Symbol(s): "a",}`)})
rambda

Version Info

Tagged at
2 months ago