Parcourir la source

Merge pull request #338 from ckeditor/i/6002

Tests: Fixed tests leaking editor instances / DOM elements. See ckeditor/ckeditor5#6002.
Kamil Piechaczek il y a 6 ans
Parent
commit
69a73b5ae6

+ 7 - 2
packages/ckeditor5-image/tests/imagecaption.js

@@ -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
@@ -25,6 +25,11 @@ describe( 'ImageCaption', () => {
 			} );
 	} );
 
+	afterEach( () => {
+		editorElement.remove();
+		return editor.destroy();
+	} );
+
 	it( 'should be loaded', () => {
 		expect( editor.plugins.get( ImageCaption ) ).to.instanceOf( ImageCaption );
 	} );

+ 3 - 2
packages/ckeditor5-image/tests/imagestyle.js

@@ -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
@@ -27,6 +27,7 @@ describe( 'ImageStyle', () => {
 	} );
 
 	afterEach( () => {
+		editorElement.remove();
 		return editor.destroy();
 	} );
 

+ 13 - 9
packages/ckeditor5-image/tests/imagestyle/imagestyleui.js

@@ -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 },
@@ -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
@@ -38,6 +38,7 @@ describe( 'ImageStyleUI', () => {
 	} );
 
 	afterEach( () => {
+		editorElement.remove();
 		return editor.destroy();
 	} );
 
@@ -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();
 			} );
 	} );
 
@@ -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();
 			} );
 	} );
 
@@ -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',
@@ -135,6 +137,8 @@ describe( 'ImageStyleUI', () => {
 						'Centered image': 'Centered image',
 						'Right aligned image': 'Right aligned image'
 					} );
+
+					return newEditor.destroy();
 				} );
 		} );
 	} );