瀏覽代碼

Added missing model selection test.

Maciej Bukowski 8 年之前
父節點
當前提交
5f81243a8a

+ 6 - 1
packages/ckeditor5-engine/src/model/selection.js

@@ -316,7 +316,12 @@ export default class Selection {
 			// We assume that the selectable is an iterable of ranges.
 			this._setRanges( selectable, backwardSelectionOrOffset );
 		} else {
-			throw new CKEditorError( 'model-selection-set-not-selectable' );
+			/**
+			 * Cannot set selection to given place.
+			 *
+			 * @error model-selection-setTo-not-selectable
+			 */
+			throw new CKEditorError( 'model-selection-setTo-not-selectable: Cannot set selection to given place.' );
 		}
 	}
 

+ 9 - 3
packages/ckeditor5-engine/tests/model/selection.js

@@ -161,7 +161,7 @@ describe( 'Selection', () => {
 		} );
 	} );
 
-	describe( 'setTo()', () => {
+	describe( 'setTo() - setting selection inside element', () => {
 		it( 'should set selection inside an element', () => {
 			const element = new Element( 'p', null, [ new Text( 'foo' ), new Text( 'bar' ) ] );
 
@@ -176,7 +176,7 @@ describe( 'Selection', () => {
 		} );
 	} );
 
-	describe( 'setTo()', () => {
+	describe( 'setTo() - setting selection on item', () => {
 		it( 'should set selection on an item', () => {
 			const textNode1 = new Text( 'foo' );
 			const textNode2 = new Text( 'bar' );
@@ -194,7 +194,7 @@ describe( 'Selection', () => {
 		} );
 	} );
 
-	describe( 'setTo - set to position or item', () => {
+	describe( 'setTo() - setting selection to position or item', () => {
 		it( 'fires change:range', () => {
 			const spy = sinon.spy();
 
@@ -580,6 +580,12 @@ describe( 'Selection', () => {
 			expect( selection._setRanges.calledOnce ).to.be.true;
 			spy.restore();
 		} );
+
+		it( 'should throw an error when trying to set selection to not selectable', () => {
+			expect( () => {
+				selection.setTo( {} );
+			} ).to.throw( /model-selection-setTo-not-selectable/ );
+		} );
 	} );
 
 	describe( 'getFirstRange()', () => {