From d3c99677851e24ec0fcbf20b5183dba28564b59d Mon Sep 17 00:00:00 2001 From: Mateusz Baginski Date: Mon, 23 Sep 2024 08:54:10 +0200 Subject: [PATCH] Add missing `editor.destroy` calls to `editor-balloon` plugin tests --- .../src/ballooneditorui.ts | 5 ++++- .../tests/ballooneditor.js | 20 ++++++++++++++++--- .../tests/ballooneditorui.js | 4 ++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/ckeditor5-editor-balloon/src/ballooneditorui.ts b/packages/ckeditor5-editor-balloon/src/ballooneditorui.ts index 82ffddb364a..ac9a2fb9bf2 100644 --- a/packages/ckeditor5-editor-balloon/src/ballooneditorui.ts +++ b/packages/ckeditor5-editor-balloon/src/ballooneditorui.ts @@ -99,7 +99,10 @@ export default class BalloonEditorUI extends EditorUI { const view = this.view; const editingView = this.editor.editing.view; - editingView.detachDomRoot( view.editable.name! ); + if ( editingView.getDomRoot( view.editable.name! ) ) { + editingView.detachDomRoot( view.editable.name! ); + } + view.destroy(); } diff --git a/packages/ckeditor5-editor-balloon/tests/ballooneditor.js b/packages/ckeditor5-editor-balloon/tests/ballooneditor.js index d135e08b09f..63f56080eed 100644 --- a/packages/ckeditor5-editor-balloon/tests/ballooneditor.js +++ b/packages/ckeditor5-editor-balloon/tests/ballooneditor.js @@ -54,6 +54,11 @@ describe( 'BalloonEditor', () => { } ); } ); + afterEach( async () => { + editor.fire( 'ready' ); + await editor.destroy(); + } ); + it( 'pushes BalloonToolbar to the list of plugins', () => { expect( editor.config.get( 'plugins' ) ).to.include( BalloonToolbar ); } ); @@ -102,28 +107,37 @@ describe( 'BalloonEditor', () => { } ); 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 BalloonEditor( editorElement ); expect( editor.config.get( 'initialData' ) ).to.equal( '

Foo

' ); + + editor.fire( 'ready' ); + await editor.destroy(); } ); - 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 BalloonEditor( '

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 BalloonEditor( 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-balloon/tests/ballooneditorui.js b/packages/ckeditor5-editor-balloon/tests/ballooneditorui.js index e7c89edf9a0..925f9cae34b 100644 --- a/packages/ckeditor5-editor-balloon/tests/ballooneditorui.js +++ b/packages/ckeditor5-editor-balloon/tests/ballooneditorui.js @@ -39,8 +39,8 @@ describe( 'BalloonEditorUI', () => { } ); } ); - afterEach( () => { - editor.destroy(); + afterEach( async () => { + await editor.destroy(); } ); describe( 'constructor()', () => {