Procházet zdrojové kódy

Fix: `InlineEditor.create()` should be able to create an instance of its subclass. Closes #25.

Piotrek Koszuliński před 8 roky
rodič
revize
ab3ae54cc1

+ 1 - 1
packages/ckeditor5-editor-inline/src/inlineeditor.js

@@ -74,7 +74,7 @@ export default class InlineEditor extends StandardEditor {
 	 */
 	 */
 	static create( element, config ) {
 	static create( element, config ) {
 		return new Promise( resolve => {
 		return new Promise( resolve => {
-			const editor = new InlineEditor( element, config );
+			const editor = new this( element, config );
 
 
 			resolve(
 			resolve(
 				editor.initPlugins()
 				editor.initPlugins()

+ 26 - 0
packages/ckeditor5-editor-inline/tests/inlineeditor.js

@@ -89,6 +89,32 @@ describe( 'InlineEditor', () => {
 		it( 'loads data from the editor element', () => {
 		it( 'loads data from the editor element', () => {
 			expect( editor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
 			expect( editor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
 		} );
 		} );
+
+		// #25
+		it( 'creates an instance of a InlineEditor child class', () => {
+			// Fun fact: Remove the next 3 lines and you'll get a lovely inf loop due to two
+			// editor being initialized on one element.
+			const editorElement = document.createElement( 'div' );
+			editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';
+
+			document.body.appendChild( editorElement );
+
+			class CustomInlineEditor extends InlineEditor {}
+
+			return CustomInlineEditor.create( editorElement, {
+				plugins: [ Paragraph, Bold ]
+			} )
+			.then( newEditor => {
+				expect( newEditor ).to.be.instanceof( CustomInlineEditor );
+				expect( newEditor ).to.be.instanceof( InlineEditor );
+
+				expect( newEditor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
+
+				editorElement.remove();
+
+				return newEditor.destroy();
+			} );
+		} );
 	} );
 	} );
 
 
 	describe( 'create - events', () => {
 	describe( 'create - events', () => {