8
0
Просмотр исходного кода

Tests: Fixed selection warnings printed in unit tests. Part of ckeditor/ckeditor5#1996.

Marek Lewandowski 6 лет назад
Родитель
Сommit
80d0b62480

+ 8 - 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,11 +599,12 @@ 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', () => {
+			// Catches the 'Trying to add a Range that is in the graveyard root. Range rejected.' warning in the CK_DEBUG mode.
+			sinon.stub( console, 'warn' );
+
+			const range = new Range( new Position( model.document.graveyard, [ 0 ] ) );
+			selection._setTo( range );
 
 			expect( selection._ranges ).to.deep.equal( [] );
 		} );

+ 6 - 1
packages/ckeditor5-engine/tests/model/operation/transform.js

@@ -3,6 +3,8 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
+/* globals console */
+
 import { transform, transformSets } from '../../../src/model/operation/transform';
 
 import Model from '../../../src/model/model';
@@ -61,6 +63,9 @@ describe( 'transform', () => {
 	};
 
 	it( 'should throw an error when one of operations is invalid', () => {
+		// Catches the 'Error during operation transformation!' warning in the CK_DEBUG mode.
+		sinon.stub( console, 'warn' );
+
 		const nodeA = new Node();
 		const nodeB = new Node();
 
@@ -80,7 +85,7 @@ describe( 'transform', () => {
 				abRelation: null,
 				baRelation: null
 			} );
-		} ).to.throw();
+		} ).to.throw( TypeError );
 	} );
 
 	describe( 'InsertOperation', () => {

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

@@ -169,11 +169,15 @@ describe( 'SelectionObserver', () => {
 
 		const selectionChangeSpy = sinon.spy();
 
+		// Catches the "Selection change observer detected an infinite rendering loop." warning in the CK_DEBUG mode.
+		sinon.stub( console, 'warn' );
+
 		viewDocument.on( 'selectionChange', selectionChangeSpy );
 
 		return new Promise( resolve => {
 			viewDocument.on( 'selectionChangeDone', () => {
 				expect( selectionChangeSpy.callCount ).to.equal( 60 );
+
 				resolve();
 			} );
 

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

@@ -473,13 +473,14 @@ describe( 'view', () => {
 		} );
 
 		it( 'should not crash when there is no selection', () => {
-			expect( () => {
-				view.change( writer => {
-					writer.setSelection( null );
-				} );
+			// Catches the `There is no selection in any editable to focus.` warning in the CK_DEBUG mode.
+			sinon.stub( console, 'warn' );
 
-				view.focus();
-			} ).not.to.throw();
+			view.change( writer => {
+				writer.setSelection( null );
+			} );
+
+			view.focus();
 		} );
 	} );