@@ -36,68 +36,68 @@ describe('.diff', () => {
36
36
[ new Date ( '2017年01月01日' ) , new Date ( '2017年01月02日' ) ] ,
37
37
[ new Date ( '2017年01月01日T00:00:00.636Z' ) , new Date ( '2017年01月01日T00:00:00.637Z' ) ] ,
38
38
] ) ( 'returns right hand side value when different to left hand side value (%s, %s)' , ( lhs , rhs ) => {
39
- expect ( diff ( lhs , rhs ) ) . toEqual ( rhs ) ;
39
+ expect ( diff ( lhs , rhs ) ) . toEqual ( lhs ) ;
40
40
} ) ;
41
41
} ) ;
42
42
} ) ;
43
43
44
44
describe ( 'recursive case' , ( ) => {
45
45
describe ( 'object' , ( ) => {
46
46
test ( "return right hand side empty object value when left hand side has been updated" , ( ) => {
47
- expect ( diff ( { a : 1 } , { a : { } } ) ) . toEqual ( { a : { } } ) ;
47
+ expect ( diff ( { a : 1 } , { a : { } } ) ) . toEqual ( { a : 1 } ) ;
48
48
} ) ;
49
49
50
50
test ( 'returns right hand side value when given objects are different' , ( ) => {
51
- expect ( diff ( { a : 1 } , { a : 2 } ) ) . toEqual ( { a : 2 } ) ;
51
+ expect ( diff ( { a : 1 } , { a : 2 } ) ) . toEqual ( { a : 1 } ) ;
52
52
} ) ;
53
53
54
54
test ( 'returns right hand side value when right hand side value is null' , ( ) => {
55
- expect ( diff ( { a : 1 } , { a : null } ) ) . toEqual ( { a : null } ) ;
55
+ expect ( diff ( { a : 1 } , { a : null } ) ) . toEqual ( { a : 1 } ) ;
56
56
} ) ;
57
57
58
58
test ( 'returns subset of right hand side value when sibling objects differ' , ( ) => {
59
- expect ( diff ( { a : { b : 1 } , c : 2 } , { a : { b : 1 } , c : 3 } ) ) . toEqual ( { c : 3 } ) ;
59
+ expect ( diff ( { a : { b : 1 } , c : 2 } , { a : { b : 1 } , c : 3 } ) ) . toEqual ( { c : 2 } ) ;
60
60
} ) ;
61
61
62
62
test ( 'returns subset of right hand side value when nested values differ' , ( ) => {
63
- expect ( diff ( { a : { b : 1 , c : 2 } } , { a : { b : 1 , c : 3 } } ) ) . toEqual ( { a : { c : 3 } } ) ;
63
+ expect ( diff ( { a : { b : 1 , c : 2 } } , { a : { b : 1 , c : 3 } } ) ) . toEqual ( { a : { c : 2 } } ) ;
64
64
} ) ;
65
65
66
66
test ( 'returns subset of right hand side value when nested values differ at multiple paths' , ( ) => {
67
- expect ( diff ( { a : { b : 1 } , c : 2 , d : { e : 100 } } , { a : { b : 99 } , c : 3 , d : { e : 100 } } ) ) . toEqual ( { a : { b : 99 } , c : 3 } ) ;
67
+ expect ( diff ( { a : { b : 1 } , c : 2 , d : { e : 100 } } , { a : { b : 99 } , c : 3 , d : { e : 100 } } ) ) . toEqual ( { a : { b : 1 } , c : 2 } ) ;
68
68
} ) ;
69
69
70
70
test ( 'returns subset of right hand side value when a key value has been deleted' , ( ) => {
71
- expect ( diff ( { a : { b : 1 } , c : 2 , d : { e : 100 } } , { a : { b : 1 } , c : 2 , d : { } } ) ) . toEqual ( { d : { e : undefined } } ) ;
71
+ expect ( diff ( { a : { b : 1 } , c : 2 , d : { e : 100 } } , { a : { b : 1 } , c : 2 , d : { } } ) ) . toEqual ( { d : { e : 100 } } ) ;
72
72
} ) ;
73
73
74
74
test ( 'returns subset of right hand side value when a key value has been added' , ( ) => {
75
- expect ( diff ( { a : 1 } , { a : 1 , b : 2 } ) ) . toEqual ( { b : 2 } ) ;
75
+ expect ( diff ( { a : 1 } , { a : 1 , b : 2 } ) ) . toEqual ( { b : undefined } ) ;
76
76
} ) ;
77
77
78
78
test ( 'returns keys as undefined when deleted from right hand side' , ( ) => {
79
- expect ( diff ( { a : 1 , b : { c : 2 } } , { a : 1 } ) ) . toEqual ( { b : undefined } ) ;
79
+ expect ( diff ( { a : 1 , b : { c : 2 } } , { a : 1 } ) ) . toEqual ( { b : { c : 2 } } ) ;
80
80
} ) ;
81
81
} ) ;
82
82
83
83
describe ( 'arrays' , ( ) => {
84
84
test ( "return right hand side empty object value when left hand side has been updated" , ( ) => {
85
- expect ( diff ( [ { a : 1 } ] , [ { a : { } } ] ) ) . toEqual ( { 0 : { a : { } } } ) ;
85
+ expect ( diff ( [ { a : 1 } ] , [ { a : { } } ] ) ) . toEqual ( { 0 : { a : 1 } } ) ;
86
86
} ) ;
87
87
test ( 'returns right hand side value as object of indices to value when arrays are different' , ( ) => {
88
- expect ( diff ( [ 1 ] , [ 2 ] ) ) . toEqual ( { 0 : 2 } ) ;
88
+ expect ( diff ( [ 1 ] , [ 2 ] ) ) . toEqual ( { 0 : 1 } ) ;
89
89
} ) ;
90
90
91
91
test ( 'returns subset of right hand side array as object of indices to value when arrays differs at multiple indicies' , ( ) => {
92
- expect ( diff ( [ 1 , 2 , 3 ] , [ 9 , 8 , 3 ] ) ) . toEqual ( { 0 : 9 , 1 : 8 } ) ;
92
+ expect ( diff ( [ 1 , 2 , 3 ] , [ 9 , 8 , 3 ] ) ) . toEqual ( { 0 : 1 , 1 : 2 } ) ;
93
93
} ) ;
94
94
95
95
test ( 'returns subset of right hand side array as object of indices to value when right hand side array has deletions' , ( ) => {
96
- expect ( diff ( [ 1 , 2 , 3 ] , [ 1 , 3 ] ) ) . toEqual ( { 1 : 3 , 2 : undefined } ) ;
96
+ expect ( diff ( [ 1 , 2 , 3 ] , [ 1 , 3 ] ) ) . toEqual ( { 1 : 2 , 2 : 3 } ) ;
97
97
} ) ;
98
98
99
99
test ( 'returns subset of right hand side array as object of indices to value when right hand side array has additions' , ( ) => {
100
- expect ( diff ( [ 1 , 2 , 3 ] , [ 1 , 2 , 3 , 9 ] ) ) . toEqual ( { 3 : 9 } ) ;
100
+ expect ( diff ( [ 1 , 2 , 3 ] , [ 1 , 2 , 3 , 9 ] ) ) . toEqual ( { 3 : undefined } ) ;
101
101
} ) ;
102
102
} ) ;
103
103
@@ -110,18 +110,18 @@ describe('.diff', () => {
110
110
} ) ;
111
111
112
112
test ( 'returns right hand side date when updated' , ( ) => {
113
- expect ( diff ( { date : lhs } , { date : rhs } ) ) . toEqual ( { date : rhs } ) ;
114
- expect ( diff ( [ lhs ] , [ rhs ] ) ) . toEqual ( { 0 : rhs } ) ;
113
+ expect ( diff ( { date : lhs } , { date : rhs } ) ) . toEqual ( { date : lhs } ) ;
114
+ expect ( diff ( [ lhs ] , [ rhs ] ) ) . toEqual ( { 0 : lhs } ) ;
115
115
} ) ;
116
116
117
117
test ( 'returns undefined when date deleted' , ( ) => {
118
- expect ( diff ( { date : lhs } , { } ) ) . toEqual ( { date : undefined } ) ;
119
- expect ( diff ( [ lhs ] , [ ] ) ) . toEqual ( { 0 : undefined } ) ;
118
+ expect ( diff ( { date : lhs } , { } ) ) . toEqual ( { date : lhs } ) ;
119
+ expect ( diff ( [ lhs ] , [ ] ) ) . toEqual ( { 0 : lhs } ) ;
120
120
} ) ;
121
121
122
122
test ( 'returns right hand side when date is added' , ( ) => {
123
- expect ( diff ( { } , { date : rhs } ) ) . toEqual ( { date : rhs } ) ;
124
- expect ( diff ( [ ] , [ rhs ] ) ) . toEqual ( { 0 : rhs } ) ;
123
+ expect ( diff ( { } , { date : rhs } ) ) . toEqual ( { date : undefined } ) ;
124
+ expect ( diff ( [ ] , [ rhs ] ) ) . toEqual ( { 0 : undefined } ) ;
125
125
} ) ;
126
126
} ) ;
127
127
@@ -131,7 +131,7 @@ describe('.diff', () => {
131
131
lhs . a = 1 ;
132
132
const rhs = Object . create ( null ) ;
133
133
rhs . a = 2 ;
134
- expect ( diff ( lhs , rhs ) ) . toEqual ( { a : 2 } ) ;
134
+ expect ( diff ( lhs , rhs ) ) . toEqual ( { a : 1 } ) ;
135
135
} ) ;
136
136
137
137
test ( 'returns subset of right hand side value when sibling objects differ' , ( ) => {
@@ -141,15 +141,15 @@ describe('.diff', () => {
141
141
const rhs = Object . create ( null ) ;
142
142
rhs . a = { b : 1 } ;
143
143
rhs . c = 3 ;
144
- expect ( diff ( lhs , rhs ) ) . toEqual ( { c : 3 } ) ;
144
+ expect ( diff ( lhs , rhs ) ) . toEqual ( { c : 2 } ) ;
145
145
} ) ;
146
146
147
147
test ( 'returns subset of right hand side value when nested values differ' , ( ) => {
148
148
const lhs = Object . create ( null ) ;
149
149
lhs . a = { b : 1 , c : 2 } ;
150
150
const rhs = Object . create ( null ) ;
151
151
rhs . a = { b : 1 , c : 3 } ;
152
- expect ( diff ( lhs , rhs ) ) . toEqual ( { a : { c : 3 } } ) ;
152
+ expect ( diff ( lhs , rhs ) ) . toEqual ( { a : { c : 2 } } ) ;
153
153
} ) ;
154
154
155
155
test ( 'returns subset of right hand side value when nested values differ at multiple paths' , ( ) => {
@@ -159,7 +159,7 @@ describe('.diff', () => {
159
159
const rhs = Object . create ( null ) ;
160
160
rhs . a = { b : 99 } ;
161
161
rhs . c = 3 ;
162
- expect ( diff ( lhs , rhs ) ) . toEqual ( { a : { b : 99 } , c : 3 } ) ;
162
+ expect ( diff ( lhs , rhs ) ) . toEqual ( { a : { b : 1 } , c : 2 } ) ;
163
163
} ) ;
164
164
165
165
test ( 'returns subset of right hand side value when a key value has been deleted' , ( ) => {
@@ -168,7 +168,7 @@ describe('.diff', () => {
168
168
lhs . c = 2 ;
169
169
const rhs = Object . create ( null ) ;
170
170
rhs . a = { b : 1 } ;
171
- expect ( diff ( lhs , rhs ) ) . toEqual ( { c : undefined } ) ;
171
+ expect ( diff ( lhs , rhs ) ) . toEqual ( { c : 2 } ) ;
172
172
} ) ;
173
173
174
174
test ( 'returns subset of right hand side value when a key value has been added' , ( ) => {
@@ -177,7 +177,7 @@ describe('.diff', () => {
177
177
const rhs = Object . create ( null ) ;
178
178
rhs . a = 1 ;
179
179
rhs . b = 2 ;
180
- expect ( diff ( lhs , rhs ) ) . toEqual ( { b : 2 } ) ;
180
+ expect ( diff ( lhs , rhs ) ) . toEqual ( { b : undefined } ) ;
181
181
} ) ;
182
182
} ) ;
183
183
} ) ;
0 commit comments