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

Commit

Permalink
Tests: Fixed selection warnings printed in unit tests. Part of ckedit…
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewand authored Sep 23, 2019
2 parents 0fae09b + 13b5f16 commit 45c82be
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
13 changes: 8 additions & 5 deletions tests/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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( [] );
} );
Expand Down
7 changes: 6 additions & 1 deletion tests/model/operation/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();

Expand All @@ -80,7 +85,7 @@ describe( 'transform', () => {
abRelation: null,
baRelation: null
} );
} ).to.throw();
} ).to.throw( TypeError );
} );

describe( 'InsertOperation', () => {
Expand Down
4 changes: 4 additions & 0 deletions tests/view/observer/selectionobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );

Expand Down
13 changes: 7 additions & 6 deletions tests/view/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
} );
} );

Expand Down

0 comments on commit 45c82be

Please sign in to comment.