浏览代码

Moved context destroy at the end of the editor destroy chain.

Oskar Wróbel 6 年之前
父节点
当前提交
2fb02da86f
共有 2 个文件被更改,包括 8 次插入7 次删除
  1. 4 5
      packages/ckeditor5-core/src/editor/editor.js
  2. 4 2
      packages/ckeditor5-core/tests/editor/editor.js

+ 4 - 5
packages/ckeditor5-core/src/editor/editor.js

@@ -252,10 +252,6 @@ export default class Editor {
 
 		return readyPromise
 			.then( () => {
-				// Remove the editor from the context.
-				// When the context was created by this editor then then the context will be destroyed.
-				return this._context._removeEditor( this );
-			} ).then( () => {
 				this.fire( 'destroy' );
 				this.stopListening();
 				this.commands.destroy();
@@ -266,7 +262,10 @@ export default class Editor {
 				this.data.destroy();
 				this.editing.destroy();
 				this.keystrokes.destroy();
-			} );
+			} )
+			// Remove the editor from the context.
+			// When the context was created by this editor then then the context will be destroyed.
+			.then( () => this._context._removeEditor( this ) );
 	}
 
 	/**

+ 4 - 2
packages/ckeditor5-core/tests/editor/editor.js

@@ -188,7 +188,7 @@ describe( 'Editor', () => {
 			expect( editor._context ).to.be.an.instanceof( Context );
 		} );
 
-		it( 'should use context given through configuration when is defined', async () => {
+		it( 'should use context given through config', async () => {
 			const context = await Context.create();
 			const editor = new TestEditor( { context } );
 
@@ -204,13 +204,15 @@ describe( 'Editor', () => {
 			}, /^context-addEditor-private-context/ );
 		} );
 
-		it( 'should destroy context created by the editor on editor destroy', async () => {
+		it( 'should destroy context created by the editor at the end of the editor destroy chain', async () => {
 			const editor = await TestEditor.create();
+			const editorPluginsDestroySpy = sinon.spy( editor.plugins, 'destroy' );
 			const contextDestroySpy = sinon.spy( editor._context, 'destroy' );
 
 			await editor.destroy();
 
 			sinon.assert.calledOnce( contextDestroySpy );
+			expect( editorPluginsDestroySpy.calledBefore( contextDestroySpy ) ).to.true;
 		} );
 
 		it( 'should not destroy context along with the editor when context was injected to the editor', async () => {