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

Commit

Permalink
Fix: Added missing return to the data initialization step.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed May 22, 2018
1 parent 5bdc338 commit 1bb57bd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/decouplededitor.js
Expand Up @@ -196,7 +196,7 @@ export default class DecoupledEditor extends Editor {
editor.fire( 'uiReady' );
} )
.then( () => {
editor.data.init( editor.element ? getDataFromElement( editor.element ) : elementOrData );
return editor.data.init( editor.element ? getDataFromElement( editor.element ) : elementOrData );
} )
.then( () => {
editor.fire( 'dataReady' );
Expand Down
35 changes: 34 additions & 1 deletion tests/decouplededitor.js
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md.
*/

/* globals document */
/* globals document, setTimeout */

import DecoupledEditorUI from '../src/decouplededitorui';
import DecoupledEditorUIView from '../src/decouplededitoruiview';
Expand Down Expand Up @@ -57,6 +57,39 @@ describe( 'DecoupledEditor', () => {
} );

describe( 'create()', () => {
it( 'should properly handled async data initialization', done => {
const spy = sinon.spy();
let resolver;

class AsyncDataInit extends Plugin {
init() {
this.editor.on( 'dataReady', () => spy( 'dataReady' ) );

this.editor.data.on( 'init', evt => {
evt.stop();
evt.return = new Promise( resolve => {
resolver = () => {
spy( 'asyncInit' );
resolve();
};
} );
}, { priority: 'high' } );
}
}

DecoupledEditor.create( '<p>foo bar</p>', {
plugins: [ Paragraph, Bold, AsyncDataInit ]
} ).then( editor => {
sinon.assert.calledWith( spy.firstCall, 'asyncInit' );
sinon.assert.calledWith( spy.secondCall, 'dataReady' );

editor.destroy().then( done );
} );

// Resolve init promise in next cycle to hold data initialization.
setTimeout( () => resolver() );
} );

describe( 'editor with data', () => {
test( () => editorData );
} );
Expand Down

0 comments on commit 1bb57bd

Please sign in to comment.