@@ -210,6 +210,83 @@ describe('fx: diff', () => {
210210
211211 expect ( result ) . toStrictEqual ( expected ) ;
212212 } ) ;
213+ it ( 'should preserve nested object values when transitioning from empty object to populated object' , ( ) => {
214+ const from = { parent : { child : { config : { } } } } ;
215+ const to = {
216+ parent : {
217+ child : {
218+ config : {
219+ annotations : { hello : 'world' } ,
220+ labels : { key : 'value' }
221+ }
222+ }
223+ }
224+ } ;
225+
226+ const result = diff ( from , to ) ;
227+ const expected = {
228+ parent : {
229+ child : {
230+ config : {
231+ annotations : { hello : 'world' } ,
232+ labels : { key : 'value' }
233+ }
234+ }
235+ }
236+ } ;
237+
238+ expect ( result ) . toStrictEqual ( expected ) ;
239+ } ) ;
240+
241+ it ( 'should preserve explicit empty object when clearing nested object values' , ( ) => {
242+ const from = { parent : { child : { config : { annotations : { hello : 'world' } } } } } ;
243+ const to = { parent : { child : { config : { } } } } ;
244+
245+ const result = diff ( from , to ) ;
246+ const expected = { parent : { child : { config : { } } } } ;
247+
248+ expect ( result ) . toStrictEqual ( expected ) ;
249+ } ) ;
250+
251+ it ( 'should not emit nested empty objects when there are no differences' , ( ) => {
252+ const from = { parent : { child : { config : { annotations : { hello : 'world' } } } } } ;
253+ const to = { parent : { child : { config : { annotations : { hello : 'world' } } } } } ;
254+
255+ const result = diff ( from , to ) ;
256+ const expected = { } ;
257+
258+ expect ( result ) . toStrictEqual ( expected ) ;
259+ } ) ;
260+
261+ it ( 'should correctly nullify nested keys when removed' , ( ) => {
262+ const from = {
263+ parent : {
264+ child : {
265+ config : {
266+ annotations : { hello : 'world' } ,
267+ labels : { key : 'value' }
268+ }
269+ }
270+ }
271+ } ;
272+ const to = { parent : { child : { config : { annotations : { hello : 'world' } } } } } ;
273+
274+ const result = diff ( from , to ) ;
275+ const expected = { parent : { child : { config : { labels : { key : null } } } } } ;
276+
277+ expect ( result ) . toStrictEqual ( expected ) ;
278+ } ) ;
279+
280+ it ( 'should not nullify child keys when parent object is updated' , ( ) => {
281+ const from = { parent : { child : { config : { } } } } ;
282+ const to = { parent : { child : { config : { annotations : { hello : 'world' } } } } } ;
283+
284+ const result = diff ( from , to ) ;
285+ const expected = { parent : { child : { config : { annotations : { hello : 'world' } } } } } ;
286+
287+ expect ( result ) . toStrictEqual ( expected ) ;
288+ expect ( result . parent . child . config ) . not . toHaveProperty ( 'annotations' , null ) ;
289+ } ) ;
213290} ) ;
214291
215292describe ( 'fx: definedKeys' , ( ) => {
0 commit comments