@@ -2,15 +2,16 @@ import preserveArray from './preserveArray';
2
2
3
3
describe ( '.preserveArray' , ( ) => {
4
4
test ( 'returns diff with nested objects converted back to arrays when property is deleted' , ( ) => {
5
- const left = { a : [ { b : [ '#' , '#' , '#' , { hello : '' } ] } , '#' , { c : '' , d : [ '#' , '' ] } , '#' ] } ;
5
+ const left = { a : [ { b : [ '#' , '#' , '#' , { hello : '' } , { hi : '' } ] } , '#' , { c : '' , d : [ '#' , '' ] } , '#' ] } ;
6
6
const right = { a : [ { b : [ '#' , '#' , '#' , { hello : 'world' } ] } , '#' , { c : 'hello' , d : [ '#' , 'bob' ] } ] } ;
7
7
const diff = {
8
8
a : {
9
9
0 : {
10
10
b : {
11
11
3 : {
12
12
hello : 'world'
13
- }
13
+ } ,
14
+ 4 : undefined
14
15
}
15
16
} ,
16
17
2 : {
@@ -31,7 +32,8 @@ describe('.preserveArray', () => {
31
32
'empty' ,
32
33
{
33
34
hello : 'world'
34
- }
35
+ } ,
36
+ undefined
35
37
]
36
38
} ,
37
39
'empty' ,
@@ -42,6 +44,8 @@ describe('.preserveArray', () => {
42
44
undefined
43
45
]
44
46
} ;
47
+
48
+ // Remove 'empty'
45
49
delete expected . a [ 0 ] . b [ 0 ] ;
46
50
delete expected . a [ 0 ] . b [ 1 ] ;
47
51
delete expected . a [ 0 ] . b [ 2 ] ;
@@ -53,13 +57,16 @@ describe('.preserveArray', () => {
53
57
54
58
test ( 'returns diff with nested objects converted back to arrays when new property is added' , ( ) => {
55
59
const left = { a : [ { b : [ '#' , '#' , '#' , { hello : '' } ] } , '#' , { c : '' , d : [ '#' , '' ] } ] } ;
56
- const right = { a : [ { b : [ '#' , '#' , '#' , { hello : 'world' } ] } , '#' , { c : 'hello' , d : [ '#' , 'bob' ] } , 'foobar' ] } ;
60
+ const right = { a : [ { b : [ '#' , '#' , '#' , { hello : 'world' } , { hi : '' } ] } , '#' , { c : 'hello' , d : [ '#' , 'bob' ] } , 'foobar' ] } ;
57
61
const diff = {
58
62
a : {
59
63
0 : {
60
64
b : {
61
65
3 : {
62
66
hello : 'world'
67
+ } ,
68
+ 4 : {
69
+ hi : ''
63
70
}
64
71
}
65
72
} ,
@@ -81,6 +88,9 @@ describe('.preserveArray', () => {
81
88
'empty' ,
82
89
{
83
90
hello : 'world'
91
+ } ,
92
+ {
93
+ hi : ''
84
94
}
85
95
]
86
96
} ,
@@ -92,6 +102,8 @@ describe('.preserveArray', () => {
92
102
'foobar'
93
103
]
94
104
} ;
105
+
106
+ // Remove 'empty'
95
107
delete expected . a [ 0 ] . b [ 0 ] ;
96
108
delete expected . a [ 0 ] . b [ 1 ] ;
97
109
delete expected . a [ 0 ] . b [ 2 ] ;
0 commit comments