Skip to content

Commit

Permalink
Global styles: Fix error when updating padding input in global styles (
Browse files Browse the repository at this point in the history
…#49465)

* Fix padding input in global styles

* Add tests

---------

Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
  • Loading branch information
andrewserong and talldan authored Mar 30, 2023
1 parent 90258ed commit ab8a510
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/block-editor/src/utils/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function normalizePath( path ) {
* @return {*} Cloned object, or original literal non-object value.
*/
function cloneObject( object ) {
if ( typeof object === 'object' ) {
if ( object && typeof object === 'object' ) {
return {
...Object.fromEntries(
Object.entries( object ).map( ( [ key, value ] ) => [
Expand Down
38 changes: 38 additions & 0 deletions packages/block-editor/src/utils/test/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit ab8a510

Please sign in to comment.