@@ -16,6 +16,7 @@ describe('.diff', () => {
16
16
[ 'object' , { a : 1 } ] ,
17
17
[ 'array' , [ 1 ] ] ,
18
18
[ 'function' , ( ) => ( { } ) ] ,
19
+ [ 'date' , new Date ( ) ] ,
19
20
] ) . it ( 'returns empty object when given values of type %s are equal' , ( type , value ) => {
20
21
expect ( diff ( value , value ) ) . to . deep . equal ( { } ) ;
21
22
} ) ;
@@ -34,6 +35,7 @@ describe('.diff', () => {
34
35
[ '872983' , { areaCode : '+44' , number : '872983' } ] ,
35
36
[ 100 , ( ) => ( { } ) ] ,
36
37
[ ( ) => ( { } ) , 100 ] ,
38
+ [ new Date ( '2017-01-01' ) , new Date ( '2017-01-02' ) ] ,
37
39
] ) . it ( 'returns right hand side value when different to left hand side value (%s, %s)' , ( lhs , rhs ) => {
38
40
expect ( diff ( lhs , rhs ) ) . to . deep . equal ( rhs ) ;
39
41
} ) ;
@@ -92,5 +94,24 @@ describe('.diff', () => {
92
94
expect ( diff ( [ 1 , 2 , 3 ] , [ 1 , 2 , 3 , 9 ] ) ) . to . deep . equal ( { 3 : 9 } ) ;
93
95
} ) ;
94
96
} ) ;
97
+
98
+ describe ( 'date' , ( ) => {
99
+ const lhs = new Date ( '2016' ) ;
100
+ const rhs = new Date ( '2017' ) ;
101
+ it ( 'returns right hand side date when updated' , ( ) => {
102
+ expect ( diff ( { date : lhs } , { date : rhs } ) ) . to . deep . equal ( { date : rhs } ) ;
103
+ expect ( diff ( [ lhs ] , [ rhs ] ) ) . to . deep . equal ( { 0 : rhs } ) ;
104
+ } ) ;
105
+
106
+ it ( 'returns undefined when date deleted' , ( ) => {
107
+ expect ( diff ( { date : lhs } , { } ) ) . to . deep . equal ( { date : undefined } ) ;
108
+ expect ( diff ( [ lhs ] , [ ] ) ) . to . deep . equal ( { 0 : undefined } ) ;
109
+ } ) ;
110
+
111
+ it ( 'returns right hand side when date is added' , ( ) => {
112
+ expect ( diff ( { } , { date : rhs } ) ) . to . deep . equal ( { date : rhs } ) ;
113
+ expect ( diff ( [ ] , [ rhs ] ) ) . to . deep . equal ( { 0 : rhs } ) ;
114
+ } ) ;
115
+ } ) ;
95
116
} ) ;
96
117
} ) ;
0 commit comments