8
0
Quellcode durchsuchen

Merge pull request #183 from ckeditor/t/182

Internal: Fixed VirtualTestEditor data#ready event. Closes #182.
Piotr Jasiun vor 6 Jahren
Ursprung
Commit
6495366297

+ 19 - 0
packages/ckeditor5-core/tests/_utils-tests/virtualtesteditor.js

@@ -41,6 +41,8 @@ describe( 'VirtualTestEditor', () => {
 			return VirtualTestEditor.create( { initialData: '<p>foo</p>', plugins: [ Paragraph ] } )
 				.then( editor => {
 					expect( editor.getData() ).to.equal( '<p>foo</p>' );
+
+					return editor.destroy();
 				} );
 		} );
 
@@ -48,6 +50,23 @@ describe( 'VirtualTestEditor', () => {
 			return VirtualTestEditor.create()
 				.then( editor => {
 					expect( editor.getData() ).to.equal( '' );
+
+					return editor.destroy();
+				} );
+		} );
+
+		it( 'fires the `data#ready` event once', () => {
+			const dataReadySpy = sinon.spy();
+
+			const Plugin = function( editor ) {
+				editor.data.on( 'ready', dataReadySpy );
+			};
+
+			return VirtualTestEditor.create( { plugins: [ Plugin ] } )
+				.then( editor => {
+					sinon.assert.calledOnce( dataReadySpy );
+
+					return editor.destroy();
 				} );
 		} );
 	} );

+ 2 - 5
packages/ckeditor5-core/tests/_utils/virtualtesteditor.js

@@ -33,14 +33,11 @@ export default class VirtualTestEditor extends Editor {
 
 			resolve(
 				editor.initPlugins()
+					.then( () => editor.data.init( config.initialData || '' ) )
 					.then( () => {
-						editor.data.init( config.initialData || '' );
-
-						// Fire `data#ready` event manually as `data#init()` method is not used.
-						editor.data.fire( 'ready' );
 						editor.fire( 'ready' );
+						return editor;
 					} )
-					.then( () => editor )
 			);
 		} );
 	}