Browse Source

Stubbed and tested console warnings.

Maciej Bukowski 6 years ago
parent
commit
48f8234fe9

+ 9 - 5
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -3,6 +3,8 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
+/* globals console */
+
 import Model from '../../src/model/model';
 import Batch from '../../src/model/batch';
 import Element from '../../src/model/element';
@@ -597,13 +599,15 @@ describe( 'DocumentSelection', () => {
 			}, /model-selection-set-ranges-not-range/, model );
 		} );
 
-		it( 'should not do nothing when trying to set selection to the graveyard', () => {
-			expect( () => {
-				const range = new Range( new Position( model.document.graveyard, [ 0 ] ) );
-				selection._setTo( range );
-			} ).to.not.throw();
+		it( 'should do nothing when trying to set selection to the graveyard', () => {
+			const consoleWarnStub = sinon.stub( console, 'warn' );
+
+			const range = new Range( new Position( model.document.graveyard, [ 0 ] ) );
+			selection._setTo( range );
 
 			expect( selection._ranges ).to.deep.equal( [] );
+			sinon.assert.calledOnce( consoleWarnStub );
+			sinon.assert.calledWith( consoleWarnStub, 'Trying to add a Range that is in the graveyard root. Range rejected.' );
 		} );
 
 		it( 'should detach removed ranges', () => {

+ 8 - 0
packages/ckeditor5-engine/tests/view/observer/selectionobserver.js

@@ -168,12 +168,20 @@ describe( 'SelectionObserver', () => {
 		} );
 
 		const selectionChangeSpy = sinon.spy();
+		const consoleWarnStub = sinon.stub( console, 'warn' );
 
 		viewDocument.on( 'selectionChange', selectionChangeSpy );
 
 		return new Promise( resolve => {
 			viewDocument.on( 'selectionChangeDone', () => {
 				expect( selectionChangeSpy.callCount ).to.equal( 60 );
+
+				sinon.assert.called( consoleWarnStub );
+				sinon.assert.calledWith(
+					consoleWarnStub,
+					'Selection change observer detected an infinite rendering loop.'
+				);
+
 				resolve();
 			} );
 

+ 9 - 6
packages/ckeditor5-engine/tests/view/view/view.js

@@ -473,13 +473,16 @@ describe( 'view', () => {
 		} );
 
 		it( 'should not crash when there is no selection', () => {
-			expect( () => {
-				view.change( writer => {
-					writer.setSelection( null );
-				} );
+			const consoleWarnStub = sinon.stub( console, 'warn' );
+
+			view.change( writer => {
+				writer.setSelection( null );
+			} );
+
+			view.focus();
 
-				view.focus();
-			} ).not.to.throw();
+			sinon.assert.calledOnce( consoleWarnStub );
+			sinon.assert.calledWith( consoleWarnStub, 'There is no selection in any editable to focus.' );
 		} );
 	} );