diff --git a/packages/ckeditor5-utils/src/config.ts b/packages/ckeditor5-utils/src/config.ts index 7a224663bcb..f34791983ca 100644 --- a/packages/ckeditor5-utils/src/config.ts +++ b/packages/ckeditor5-utils/src/config.ts @@ -272,15 +272,16 @@ export default class Config { * Clones configuration object or value. */ function cloneConfig( source: T ): T { - return cloneDeepWith( source, leaveDOMReferences ); + return cloneDeepWith( source, leaveItemReferences ); } /** * A customized function for cloneDeepWith. - * It will leave references to DOM Elements instead of cloning them. + * In case if it's a DOM Element it will leave references to DOM Elements instead of cloning them. + * If it's a function it will leave reference to actuall function. */ -function leaveDOMReferences( value: unknown ): unknown { - return isElement( value ) ? value : undefined; +function leaveItemReferences( value: unknown ): unknown { + return isElement( value ) || typeof value === 'function' ? value : undefined; } /** diff --git a/packages/ckeditor5-utils/tests/config.js b/packages/ckeditor5-utils/tests/config.js index b5bbabee106..25f05b8f6b1 100644 --- a/packages/ckeditor5-utils/tests/config.js +++ b/packages/ckeditor5-utils/tests/config.js @@ -28,8 +28,10 @@ describe( 'Config', () => { { bar: 'b' }, { bar: 'a' }, { bar: 'z' } - ] - } + ], + callback: () => null + }, + callback: () => null } ); } ); @@ -363,6 +365,16 @@ describe( 'Config', () => { expect( config.get( 'resize.icon.path' ) ).to.equal( 'xyz' ); } ); + it( 'should return a function', () => { + expect( typeof config.get( 'callback' ) ).to.equal( 'function' ); + expect( config.get( 'callback' )() ).to.equal( null ); + } ); + + it( 'should return a function nested in option', () => { + expect( typeof config.get( 'options.callback' ) ).to.equal( 'function' ); + expect( config.get( 'options.callback' )() ).to.equal( null ); + } ); + it( 'should retrieve an object of the configuration', () => { const resize = config.get( 'resize' ); @@ -482,7 +494,9 @@ describe( 'Config', () => { describe( 'names()', () => { it( 'should return an iterator of top level names of the configuration', () => { - expect( Array.from( config.names() ) ).to.be.deep.equal( [ 'creator', 'language', 'resize', 'toolbar', 'options' ] ); + expect( Array.from( config.names() ) ).to.be.deep.equal( + [ 'creator', 'language', 'resize', 'toolbar', 'options', 'callback' ] + ); } ); } ); } );