Преглед на файлове

Used secureSourceElement() as a helper.

Aleksander Nowodzinski преди 6 години
родител
ревизия
74f7682c13
променени са 2 файла, в които са добавени 16 реда и са изтрити 6 реда
  1. 2 1
      packages/ckeditor5-editor-balloon/src/ballooneditor.js
  2. 14 5
      packages/ckeditor5-editor-balloon/tests/ballooneditor.js

+ 2 - 1
packages/ckeditor5-editor-balloon/src/ballooneditor.js

@@ -20,6 +20,7 @@ import attachToForm from '@ckeditor/ckeditor5-core/src/editor/utils/attachtoform
 import mix from '@ckeditor/ckeditor5-utils/src/mix';
 import { isElement } from 'lodash-es';
 import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+import secureSourceElement from '@ckeditor/ckeditor5-core/src/editor/utils/securesourceelement';
 
 /**
  * The {@glink builds/guides/overview#balloon-editor balloon editor} implementation (Medium-like editor).
@@ -66,7 +67,7 @@ export default class BalloonEditor extends Editor {
 
 		if ( isElement( sourceElementOrData ) ) {
 			this.sourceElement = sourceElementOrData;
-			this.secureSourceElement();
+			secureSourceElement( this );
 		}
 
 		const plugins = this.config.get( 'plugins' );

+ 14 - 5
packages/ckeditor5-editor-balloon/tests/ballooneditor.js

@@ -19,7 +19,6 @@ import DataApiMixin from '@ckeditor/ckeditor5-core/src/editor/utils/dataapimixin
 import ElementApiMixin from '@ckeditor/ckeditor5-core/src/editor/utils/elementapimixin';
 import RootElement from '@ckeditor/ckeditor5-engine/src/model/rootelement';
 
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
 import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
@@ -89,10 +88,20 @@ describe( 'BalloonEditor', () => {
 		} );
 
 		// See: https://github.com/ckeditor/ckeditor5/issues/746
-		it( 'should throw when trying to create the editor using the same source element more than once', () => {
-			expect( () => {
-				new BalloonEditor( editorElement, { plugins: [] } ); // eslint-disable-line no-new
-			} ).to.throw( CKEditorError, /^editor-source-element-used-more-than-once/ );
+		it( 'should throw when trying to create the editor using the same source element more than once', done => {
+			BalloonEditor.create( editorElement )
+				.then(
+					() => {
+						expect.fail( 'Balloon editor should not initialize on an element already used by other instance.' );
+					},
+					err => {
+						assertCKEditorError( err,
+							/^editor-source-element-used-more-than-once/
+						);
+					}
+				)
+				.then( done )
+				.catch( done );
 		} );
 	} );