From 1a253a203b77f437566c2151b0d7a6670a3ba3ff Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Thu, 30 Mar 2023 15:12:57 +0800 Subject: [PATCH] Add tests --- .../block-editor/src/utils/test/object.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/packages/block-editor/src/utils/test/object.js b/packages/block-editor/src/utils/test/object.js index be5360064ac08..14562400741b5 100644 --- a/packages/block-editor/src/utils/test/object.js +++ b/packages/block-editor/src/utils/test/object.js @@ -84,6 +84,44 @@ describe( 'immutableSet', () => { } ); } ); } ); + + describe( 'for nested falsey values', () => { + it( 'overwrites undefined values', () => { + const result = immutableSet( { test: undefined }, 'test', 1 ); + + expect( result ).toEqual( { test: 1 } ); + } ); + + it( 'overwrites null values', () => { + const result = immutableSet( { test: null }, 'test', 1 ); + + expect( result ).toEqual( { test: 1 } ); + } ); + + it( 'overwrites false values', () => { + const result = immutableSet( { test: false }, 'test', 1 ); + + expect( result ).toEqual( { test: 1 } ); + } ); + + it( 'overwrites `0` values', () => { + const result = immutableSet( { test: 0 }, 'test', 1 ); + + expect( result ).toEqual( { test: 1 } ); + } ); + + it( 'overwrites empty string values', () => { + const result = immutableSet( { test: '' }, 'test', 1 ); + + expect( result ).toEqual( { test: 1 } ); + } ); + + it( 'overwrites NaN values', () => { + const result = immutableSet( { test: NaN }, 'test', 1 ); + + expect( result ).toEqual( { test: 1 } ); + } ); + } ); } ); describe( 'does not mutate the original object', () => {