Browse Source

Tests: Added tests for `Context#editors`. Fixed some failing tests.

Szymon Cofalik 6 years ago
parent
commit
930b6bda95

+ 20 - 0
packages/ckeditor5-core/tests/context.js

@@ -49,6 +49,26 @@ describe( 'Context', () => {
 		} );
 	} );
 
+	describe( 'editors', () => {
+		it( 'should keep all the editors created within the context and fire event:add whenever an editor is added', async () => {
+			const spy = sinon.spy();
+			const context = await Context.create();
+
+			context.editors.on( 'add', spy );
+
+			const editorA = await VirtualTestEditor.create( { context } );
+
+			expect( spy.calledOnce );
+
+			const editorB = await VirtualTestEditor.create( { context } );
+
+			expect( spy.calledTwice );
+
+			expect( context.editors.has( editorA ) );
+			expect( context.editors.has( editorB ) );
+		} );
+	} );
+
 	describe( 'locale', () => {
 		it( 'is instantiated and t() is exposed', () => {
 			const context = new Context();

+ 8 - 1
packages/ckeditor5-core/tests/editor/utils/attachtoform.js

@@ -43,7 +43,9 @@ describe( 'attachToForm()', () => {
 		submitStub.restore();
 		form.remove();
 
-		return editor.destroy();
+		if ( editor ) {
+			return editor.destroy();
+		}
 	} );
 
 	it( 'should throw an error when is used with editor without `ElementApiMixin`', () => {
@@ -126,6 +128,7 @@ describe( 'attachToForm()', () => {
 		expect( textarea.value ).to.equal( '' );
 
 		return editor.destroy().then( () => {
+			editor = null;
 			// Submit method is no longer replaced by our implementation.
 			expect( form.submit ).to.equal( submitStub );
 			form.submit();
@@ -141,6 +144,8 @@ describe( 'attachToForm()', () => {
 		expect( textarea.value ).to.equal( '' );
 
 		return editor.destroy().then( () => {
+			editor = null;
+
 			form.dispatchEvent( new Event( 'submit', {
 				// We need to be able to do preventDefault() to prevent page reloads in Firefox.
 				cancelable: true
@@ -172,6 +177,8 @@ describe( 'attachToForm()', () => {
 		expect( textarea.value ).to.equal( 'foo bar' );
 
 		return editor.destroy().then( () => {
+			editor = null;
+
 			expect( form.submit ).to.equal( input );
 			input.remove();
 		} );

+ 2 - 0
packages/ckeditor5-core/tests/editor/utils/securesourceelement.js

@@ -53,6 +53,8 @@ describe( 'secureSourceElement()', () => {
 
 		return editor.destroy()
 			.then( () => {
+				editor = null;
+
 				expect( sourceElement.ckeditorInstance ).to.be.undefined;
 			} );
 	} );