Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 1da0563

Browse files
committed
Fix: InlineEditor.create() should be able to create an instance of its subclass. Closes #25.
1 parent 6ca2014 commit 1da0563

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/inlineeditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default class InlineEditor extends StandardEditor {
7474
*/
7575
static create( element, config ) {
7676
return new Promise( resolve => {
77-
const editor = new InlineEditor( element, config );
77+
const editor = new this( element, config );
7878

7979
resolve(
8080
editor.initPlugins()

tests/inlineeditor.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,32 @@ describe( 'InlineEditor', () => {
8989
it( 'loads data from the editor element', () => {
9090
expect( editor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
9191
} );
92+
93+
// #25
94+
it( 'creates an instance of a InlineEditor child class', () => {
95+
// Fun fact: Remove the next 3 lines and you'll get a lovely inf loop due to two
96+
// editor being initialized on one element.
97+
const editorElement = document.createElement( 'div' );
98+
editorElement.innerHTML = '<p><strong>foo</strong> bar</p>';
99+
100+
document.body.appendChild( editorElement );
101+
102+
class CustomInlineEditor extends InlineEditor {}
103+
104+
return CustomInlineEditor.create( editorElement, {
105+
plugins: [ Paragraph, Bold ]
106+
} )
107+
.then( newEditor => {
108+
expect( newEditor ).to.be.instanceof( CustomInlineEditor );
109+
expect( newEditor ).to.be.instanceof( InlineEditor );
110+
111+
expect( newEditor.getData() ).to.equal( '<p><strong>foo</strong> bar</p>' );
112+
113+
editorElement.remove();
114+
115+
return newEditor.destroy();
116+
} );
117+
} );
92118
} );
93119

94120
describe( 'create - events', () => {

0 commit comments

Comments
 (0)