Browse Source

Editor#destroy() will not blow up when editor was initialized with the data.

Kamil Piechaczek 7 years ago
parent
commit
75e763770d

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

@@ -97,7 +97,11 @@ export default class InlineEditor extends Editor {
 		this.ui.destroy();
 
 		return super.destroy()
-			.then( () => setDataInElement( this.sourceElement, data ) );
+			.then( () => {
+				if ( this.sourceElement ) {
+					setDataInElement( this.sourceElement, data );
+				}
+			} );
 	}
 
 	/**

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

@@ -288,5 +288,13 @@ describe( 'InlineEditor', () => {
 						.to.equal( '<p>a</p><heading>b</heading>' );
 				} );
 		} );
+
+		it( 'should not throw an error if editor was initialized with the data', () => {
+			return InlineEditor
+				.create( '<p>Foo.</p>', {
+					plugins: [ Paragraph, Bold ]
+				} )
+				.then( newEditor => newEditor.destroy() );
+		} );
 	} );
 } );