File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 8
8
getOrderIndependentHash ,
9
9
arrayRemove ,
10
10
revertArrayChange ,
11
+ deepClone ,
11
12
} from '../utils' ;
12
13
13
14
describe ( 'utils' , ( ) => {
@@ -172,4 +173,42 @@ describe('utils', () => {
172
173
expect ( revertedEdited ) . toEqual ( [ 1 , 2 , 3 , 5 ] ) ;
173
174
expect ( revertedArray ) . toEqual ( [ [ 1 , 2 ] , [ 1 , 2 ] ] ) ;
174
175
} ) ;
176
+
177
+ it ( 'deepClone()' , ( ) => {
178
+ const obj = {
179
+ str : '123' ,
180
+ num : 123 ,
181
+ reg : / 1 2 3 / ,
182
+ arr : [ 1 , 2 , 3 ] ,
183
+ date : new Date ( '2019-01-05' ) ,
184
+ obj : {
185
+ a : {
186
+ b : 1 ,
187
+ } ,
188
+ } ,
189
+ } ;
190
+
191
+ const clone = deepClone ( obj ) ;
192
+ expect ( obj ) . toEqual ( {
193
+ arr : [ 1 , 2 , 3 ] ,
194
+ date : new Date ( '2019-01-05T00:00:00.000Z' ) ,
195
+ num : 123 ,
196
+ obj : { a : { b : 1 } } ,
197
+ reg : / 1 2 3 / ,
198
+ str : '123' ,
199
+ } ) ;
200
+ expect ( clone === obj ) . toBeFalsy ( ) ;
201
+ expect ( clone ) . toEqual ( {
202
+ arr : [ 1 , 2 , 3 ] ,
203
+ date : new Date ( '2019-01-05T00:00:00.000Z' ) ,
204
+ num : 123 ,
205
+ obj : { a : { b : 1 } } ,
206
+ reg : / 1 2 3 / ,
207
+ str : '123' ,
208
+ } ) ;
209
+ clone . date = new Date ( '2019-01-06' ) ;
210
+ clone . obj . a . b = 2 ;
211
+ expect ( obj . date ) . toEqual ( new Date ( '2019-01-05T00:00:00.000Z' ) ) ;
212
+ expect ( obj . obj . a . b ) . toBe ( 1 ) ;
213
+ } ) ;
175
214
} ) ;
You can’t perform that action at this time.
0 commit comments