Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #338 from ckeditor/i/6002
Browse files Browse the repository at this point in the history
Tests: Fixed tests leaking editor instances / DOM elements. See ckeditor/ckeditor5#6002.
  • Loading branch information
pomek authored Dec 20, 2019
2 parents 757dfcd + 990f240 commit 6fe524c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
9 changes: 7 additions & 2 deletions tests/imagecaption.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import ImageCaption from '../src/imagecaption';
import ImageCaptionEditing from '../src/imagecaption/imagecaptionediting';

describe( 'ImageCaption', () => {
let editor;
let editor, editorElement;

beforeEach( () => {
const editorElement = window.document.createElement( 'div' );
editorElement = window.document.createElement( 'div' );
window.document.body.appendChild( editorElement );

return ClassicTestEditor
Expand All @@ -25,6 +25,11 @@ describe( 'ImageCaption', () => {
} );
} );

afterEach( () => {
editorElement.remove();
return editor.destroy();
} );

it( 'should be loaded', () => {
expect( editor.plugins.get( ImageCaption ) ).to.instanceOf( ImageCaption );
} );
Expand Down
5 changes: 3 additions & 2 deletions tests/imagestyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import ImageStyleUI from '../src/imagestyle/imagestyleui';
import global from '@ckeditor/ckeditor5-utils/src/dom/global';

describe( 'ImageStyle', () => {
let editor;
let editor, editorElement;

beforeEach( () => {
const editorElement = global.document.createElement( 'div' );
editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );

return ClassicTestEditor
Expand All @@ -27,6 +27,7 @@ describe( 'ImageStyle', () => {
} );

afterEach( () => {
editorElement.remove();
return editor.destroy();
} );

Expand Down
22 changes: 13 additions & 9 deletions tests/imagestyle/imagestyleui.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';

describe( 'ImageStyleUI', () => {
let editor;
let editor, editorElement;

const styles = [
{ name: 'style 1', title: 'Style 1 title', icon: 'style1-icon', isDefault: true },
Expand All @@ -22,7 +22,7 @@ describe( 'ImageStyleUI', () => {
];

beforeEach( () => {
const editorElement = global.document.createElement( 'div' );
editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );

return ClassicTestEditor
Expand All @@ -38,6 +38,7 @@ describe( 'ImageStyleUI', () => {
} );

afterEach( () => {
editorElement.remove();
return editor.destroy();
} );

Expand Down Expand Up @@ -91,11 +92,12 @@ describe( 'ImageStyleUI', () => {
}
} )
.then( newEditor => {
editor = newEditor;

const buttonView = editor.ui.componentFactory.create( 'imageStyle:style 1' );
const buttonView = newEditor.ui.componentFactory.create( 'imageStyle:style 1' );

expect( buttonView.label ).to.equal( 'Default title' );

editorElement.remove();
return newEditor.destroy();
} );
} );

Expand All @@ -113,7 +115,9 @@ describe( 'ImageStyleUI', () => {
} )
.then( newEditor => {
expect( newEditor.config.get( 'image.toolbar' ) ).to.deep.equal( [ 'foo', 'bar' ] );
newEditor.destroy();

editorElement.remove();
return newEditor.destroy();
} );
} );

Expand All @@ -124,9 +128,7 @@ describe( 'ImageStyleUI', () => {
plugins: [ ImageStyleUI ]
} )
.then( newEditor => {
editor = newEditor;

const plugin = editor.plugins.get( ImageStyleUI );
const plugin = newEditor.plugins.get( ImageStyleUI );

expect( plugin.localizedDefaultStylesTitles ).to.deep.equal( {
'Full size image': 'Full size image',
Expand All @@ -135,6 +137,8 @@ describe( 'ImageStyleUI', () => {
'Centered image': 'Centered image',
'Right aligned image': 'Right aligned image'
} );

return newEditor.destroy();
} );
} );
} );
Expand Down

0 comments on commit 6fe524c

Please sign in to comment.