Browse Source

Fixed: Broken test due to ui.destroy() call when ui is null.

Aleksander Nowodzinski 10 năm trước cách đây
mục cha
commit
478b4520d4

+ 10 - 2
packages/ckeditor5-engine/src/creator.js

@@ -49,9 +49,17 @@ export default class Creator extends Plugin {
 		}
 
 		const ui = this.editor.ui;
-		this.editor.ui = null;
+		let promise = Promise.resolve();
+
+		if ( ui ) {
+			promise = promise
+				.then( ui.destroy.bind( ui ) )
+				.then( () => {
+					this.editor.ui = null;
+				} );
+		}
 
-		return ui.destroy();
+		return promise;
 	}
 
 	/**

+ 21 - 6
packages/ckeditor5-engine/tests/creator/creator.js

@@ -60,20 +60,35 @@ describe( 'Creator', () => {
 			expect( pluginSpy.called ).to.be.true;
 		} );
 
-		it( 'should destroy the UI', () => {
-			const uiSpy = sinon.stub().returns( new Promise( () => {} ) );
+		it( 'should destroy the UI (sync)', () => {
+			const uiSpy = sinon.spy();
 
 			editor.ui = {
 				destroy: uiSpy
 			};
 
-			creator.destroy();
+			return creator.destroy()
+				.then( () => {
+					expect( uiSpy.called ).to.be.true;
+					expect( editor.ui ).to.be.null;
+				} );
+		} );
+
+		it( 'should destroy the UI (async)', () => {
+			const uiSpy = sinon.stub().returns( Promise.resolve() );
 
-			expect( uiSpy.called ).to.be.true;
-			expect( editor.ui ).to.be.null;
+			editor.ui = {
+				destroy: uiSpy
+			};
+
+			return creator.destroy()
+				.then( () => {
+					expect( uiSpy.called ).to.be.true;
+					expect( editor.ui ).to.be.null;
+				} );
 		} );
 
-		it( 'should wait until UI is destroyed', () => {
+		it( 'should wait until UI is destroyed (async)', () => {
 			let resolved = false;
 			let resolve;
 			const uiSpy = sinon.stub().returns(