diff --git a/packages/ckeditor5-editor-classic/src/classiceditorui.ts b/packages/ckeditor5-editor-classic/src/classiceditorui.ts index 6eac1638127..db193c5bd69 100644 --- a/packages/ckeditor5-editor-classic/src/classiceditorui.ts +++ b/packages/ckeditor5-editor-classic/src/classiceditorui.ts @@ -137,7 +137,11 @@ export default class ClassicEditorUI extends EditorUI { const editingView = this.editor.editing.view; this._elementReplacer.restore(); - editingView.detachDomRoot( view.editable.name! ); + + if ( editingView.getDomRoot( view.editable.name! ) ) { + editingView.detachDomRoot( view.editable.name! ); + } + view.destroy(); } diff --git a/packages/ckeditor5-editor-classic/tests/classiceditor.js b/packages/ckeditor5-editor-classic/tests/classiceditor.js index a73fc5a64d6..bbe254a7c04 100644 --- a/packages/ckeditor5-editor-classic/tests/classiceditor.js +++ b/packages/ckeditor5-editor-classic/tests/classiceditor.js @@ -48,6 +48,13 @@ describe( 'ClassicEditor', () => { editor = new ClassicEditor( editorElement ); } ); + afterEach( async () => { + if ( editor.state !== 'destroyed' ) { + editor.fire( 'ready' ); + await editor.destroy(); + } + } ); + it( 'uses HTMLDataProcessor', () => { expect( editor.data.processor ).to.be.instanceof( HtmlDataProcessor ); } ); @@ -102,16 +109,19 @@ describe( 'ClassicEditor', () => { } ); describe( 'automatic toolbar items groupping', () => { - it( 'should be on by default', () => { + it( 'should be on by default', async () => { const editorElement = document.createElement( 'div' ); const editor = new ClassicEditor( editorElement ); expect( editor.ui.view.toolbar.options.shouldGroupWhenFull ).to.be.true; + editor.fire( 'ready' ); + await editor.destroy(); + editorElement.remove(); } ); - it( 'can be disabled using config.toolbar.shouldNotGroupWhenFull', () => { + it( 'can be disabled using config.toolbar.shouldNotGroupWhenFull', async () => { const editorElement = document.createElement( 'div' ); const editor = new ClassicEditor( editorElement, { toolbar: { @@ -121,34 +131,48 @@ describe( 'ClassicEditor', () => { expect( editor.ui.view.toolbar.options.shouldGroupWhenFull ).to.be.false; + editor.fire( 'ready' ); + await editor.destroy(); + editorElement.remove(); } ); } ); } ); describe( 'config.initialData', () => { - it( 'if not set, is set using DOM element data', () => { + it( 'if not set, is set using DOM element data', async () => { const editorElement = document.createElement( 'div' ); editorElement.innerHTML = '

Foo

'; const editor = new ClassicEditor( editorElement ); expect( editor.config.get( 'initialData' ) ).to.equal( '

Foo

' ); + + editor.fire( 'ready' ); + await editor.destroy(); + + editorElement.remove(); } ); - it( 'if not set, is set using data passed in constructor', () => { + it( 'if not set, is set using data passed in constructor', async () => { const editor = new ClassicEditor( '

Foo

' ); expect( editor.config.get( 'initialData' ) ).to.equal( '

Foo

' ); + + editor.fire( 'ready' ); + await editor.destroy(); } ); - it( 'if set, is not overwritten with DOM element data', () => { + it( 'if set, is not overwritten with DOM element data', async () => { const editorElement = document.createElement( 'div' ); editorElement.innerHTML = '

Foo

'; const editor = new ClassicEditor( editorElement, { initialData: '

Bar

' } ); expect( editor.config.get( 'initialData' ) ).to.equal( '

Bar

' ); + + editor.fire( 'ready' ); + await editor.destroy(); } ); it( 'it should throw if config.initialData is set and initial data is passed in constructor', () => { diff --git a/packages/ckeditor5-editor-classic/tests/classiceditorui.js b/packages/ckeditor5-editor-classic/tests/classiceditorui.js index 46047b15038..a6833b59765 100644 --- a/packages/ckeditor5-editor-classic/tests/classiceditorui.js +++ b/packages/ckeditor5-editor-classic/tests/classiceditorui.js @@ -41,8 +41,8 @@ describe( 'ClassicEditorUI', () => { } ); } ); - afterEach( () => { - editor.destroy(); + afterEach( async () => { + await editor.destroy(); } ); describe( 'constructor()', () => {