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

dissocPath.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
const assert = require('assert')import { eq } from './_internals/testUtils.js'import { dissocPath } from './dissocPath.js'
const testInput = { a : { b : 1, c : 2, d : { e : 3 }, }, f : [ { g : 4 }, { h : 5, i : 6, j : { k : 7, l : 8, }, }, ], m : 9,}
test('update array', () => { const expected = { a : { b : 1, c : 2, d : { e : 3 }, }, f : [ { g : 4 }, { h : 5, j : { k : 7, l : 8, }, }, ], m : 9, } const result = dissocPath('f.1.i', testInput) expect(result).toEqual(expected)})
test('update object', () => { const result = dissocPath('a.b', testInput) const expected = { a : { c : 2, d : { e : 3 }, }, f : [ { g : 4 }, { h : 5, i : 6, j : { k : 7, l : 8, }, }, ], m : 9, } expect(result).toEqual(expected)})
test('does not try to omit inner properties that do not exist', () => { const obj1 = { a : 1, b : { c : 2, d : 3, }, e : 4, f : 5, } const obj2 = dissocPath([ 'x', 0, 'z' ], obj1) eq(obj2, { a : 1, b : { c : 2, d : 3, }, e : 4, f : 5, }) // Note: reference equality below! assert.strictEqual(obj2.a, obj1.a) assert.strictEqual(obj2.b, obj1.b) assert.strictEqual(obj2.f, obj1.f)})
test('leaves an empty object when all properties omitted', () => { const obj1 = { a : 1, b : { c : 2 }, d : 3, } const obj2 = dissocPath([ 'b', 'c' ], obj1) eq(obj2, { a : 1, b : {}, d : 3, })})
test('leaves an empty array when all indexes are omitted', () => { const obj1 = { a : 1, b : [ 2 ], d : 3, } const obj2 = dissocPath([ 'b', 0 ], obj1) eq(obj2, { a : 1, b : [], d : 3, })})
test('accepts empty path', () => { eq(dissocPath([], { a : 1, b : 2, }), { a : 1, b : 2, })})
test('allow integer to be used as key for object', () => { eq(dissocPath([ 42 ], { 42 : 3, a : 1, b : 2, }), { a : 1, b : 2, })})
test('support remove null/undefined value path', () => { eq(dissocPath([ 'c', 'd' ], { a : 1, b : 2, c : null, }), { a : 1, b : 2, c : null, }) eq(dissocPath([ 'c', 'd' ], { a : 1, b : 2, c : undefined, }), { a : 1, b : 2, c : undefined, })
const obj1 = { a : 1, b : 2, } const obj2 = dissocPath([ 'c', 'd' ], obj1)
eq(obj2, obj1)
// NOTE: commented out on purpose // assert.notStrictEqual(obj2, obj1)})
rambda

Version Info

Tagged at
2 months ago