File tree Expand file tree Collapse file tree 2 files changed +35
-4
lines changed Expand file tree Collapse file tree 2 files changed +35
-4
lines changed Original file line number Diff line number Diff line change 1
- import { isEmpty , isObject } from '../utils' ;
1
+ import { isEmpty , isObject , properObject } from '../utils' ;
2
2
3
3
const deletedDiff = ( lhs , rhs ) => {
4
4
if ( lhs === rhs || ! isObject ( lhs ) || ! isObject ( rhs ) ) return { } ;
5
5
6
- return Object . keys ( lhs ) . reduce ( ( acc , key ) => {
7
- if ( rhs . hasOwnProperty ( key ) ) {
8
- const difference = deletedDiff ( lhs [ key ] , rhs [ key ] ) ;
6
+ const l = properObject ( lhs ) ;
7
+ const r = properObject ( rhs ) ;
8
+
9
+ return Object . keys ( l ) . reduce ( ( acc , key ) => {
10
+ if ( r . hasOwnProperty ( key ) ) {
11
+ const difference = deletedDiff ( l [ key ] , r [ key ] ) ;
9
12
10
13
if ( isObject ( difference ) && isEmpty ( difference ) ) return acc ;
11
14
Original file line number Diff line number Diff line change @@ -81,5 +81,33 @@ describe('.deletedDiff', () => {
81
81
expect ( deletedDiff ( [ new Date ( '2016' ) ] , [ ] ) ) . toEqual ( { 0 : undefined } ) ;
82
82
} ) ;
83
83
} ) ;
84
+
85
+ describe ( 'object create null' , ( ) => {
86
+ test ( 'returns keys as undefined when deleted from right hand side root' , ( ) => {
87
+ const lhs = Object . create ( null ) ;
88
+ const rhs = Object . create ( null ) ;
89
+ lhs . a = 1 ;
90
+ lhs . b = 2 ;
91
+ rhs . a = 1 ;
92
+ expect ( deletedDiff ( lhs , rhs ) ) . toEqual ( { b : undefined } ) ;
93
+ } ) ;
94
+
95
+ test ( 'returns keys as undefined when deeply deleted from right hand side' , ( ) => {
96
+ const lhs = Object . create ( null ) ;
97
+ const rhs = Object . create ( null ) ;
98
+ lhs . a = { b : 1 } ;
99
+ lhs . c = { d : 100 } ;
100
+ rhs . a = { b : 1 } ;
101
+ rhs . c = { } ;
102
+ expect ( deletedDiff ( lhs , rhs ) ) . toEqual ( { c : { d : undefined } } ) ;
103
+ } ) ;
104
+
105
+ test ( 'returns subset of right hand side with deleted date' , ( ) => {
106
+ const lhs = Object . create ( null ) ;
107
+ const rhs = Object . create ( null ) ;
108
+ lhs . date = new Date ( '2016' ) ;
109
+ expect ( deletedDiff ( { date : new Date ( '2016' ) } , rhs ) ) . toEqual ( { date : undefined } ) ;
110
+ } ) ;
111
+ } ) ;
84
112
} ) ;
85
113
} ) ;
You can’t perform that action at this time.
0 commit comments