Bladeren bron

Fixed model tests.

Maciej Bukowski 6 jaren geleden
bovenliggende
commit
57d2396204

+ 11 - 4
packages/ckeditor5-engine/src/model/position.js

@@ -61,7 +61,7 @@ export default class Position {
 			 *
 			 * @error model-position-root-invalid
 			 */
-			throw new CKEditorError( 'model-position-root-invalid: Position root invalid.', this );
+			throw new CKEditorError( 'model-position-root-invalid: Position root invalid.', null );
 		}
 
 		if ( !( path instanceof Array ) || path.length === 0 ) {
@@ -71,7 +71,10 @@ export default class Position {
 			 * @error model-position-path-incorrect
 			 * @param path
 			 */
-			throw new CKEditorError( 'model-position-path-incorrect: Position path must be an array with at least one item.', this, { path } );
+			throw new CKEditorError(
+				'model-position-path-incorrect: Position path must be an array with at least one item.',
+				null, { path }
+			);
 		}
 
 		// Normalize the root and path (if element was passed).
@@ -859,7 +862,8 @@ export default class Position {
 				throw new CKEditorError(
 					'model-createPositionAt-offset-required: ' +
 					'Model#createPositionAt() requires the offset when the first parameter is a model item.',
-					this );
+					this
+				);
 			}
 
 			if ( !node.is( 'element' ) && !node.is( 'documentFragment' ) ) {
@@ -868,7 +872,10 @@ export default class Position {
 				 *
 				 * @error model-position-parent-incorrect
 				 */
-				throw new CKEditorError( 'model-position-parent-incorrect: Position parent have to be a element or document fragment.', this );
+				throw new CKEditorError(
+					'model-position-parent-incorrect: Position parent have to be a element or document fragment.',
+					this
+				);
 			}
 
 			const path = node.getPath();

+ 2 - 2
packages/ckeditor5-engine/tests/model/documentfragment.js

@@ -113,11 +113,11 @@ describe( 'DocumentFragment', () => {
 		it( 'should throw if given offset is too high or too low', () => {
 			expectToThrowCKEditorError( () => {
 				frag.offsetToIndex( -1 );
-			}, /nodelist-offset-out-of-bounds/, null );
+			}, /nodelist-offset-out-of-bounds/, frag );
 
 			expectToThrowCKEditorError( () => {
 				frag.offsetToIndex( 55 );
-			}, /nodelist-offset-out-of-bounds/, null );
+			}, /nodelist-offset-out-of-bounds/, frag );
 		} );
 
 		it( 'should return length if given offset is equal to maxOffset', () => {

+ 1 - 0
packages/ckeditor5-engine/tests/model/documentselection.js

@@ -19,6 +19,7 @@ import Collection from '@ckeditor/ckeditor5-utils/src/collection';
 import count from '@ckeditor/ckeditor5-utils/src/count';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { setData, getData } from '../../src/dev-utils/model';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'DocumentSelection', () => {
 	let model, doc, root, selection, liveRange, range;

+ 2 - 2
packages/ckeditor5-engine/tests/model/element.js

@@ -303,11 +303,11 @@ describe( 'Element', () => {
 		it( 'should throw if given offset is too high or too low', () => {
 			expectToThrowCKEditorError( () => {
 				element.offsetToIndex( -1 );
-			}, /nodelist-offset-out-of-bounds/, null );
+			}, /nodelist-offset-out-of-bounds/, element );
 
 			expectToThrowCKEditorError( () => {
 				element.offsetToIndex( 55 );
-			}, /nodelist-offset-out-of-bounds/, null );
+			}, /nodelist-offset-out-of-bounds/, element );
 		} );
 
 		it( 'should return length if given offset is equal to maxOffset', () => {

+ 1 - 1
packages/ckeditor5-engine/tests/model/liveposition.js

@@ -44,7 +44,7 @@ describe( 'LivePosition', () =>
 	it( 'should throw if given root is not a RootElement', () => {
 		expectToThrowCKEditorError( () => {
 			new LivePosition( new DocumentFragment(), [ 1 ] ); // eslint-disable-line no-new
-		}, /model-liveposition-root-not-rootelement/, null );
+		}, /model-liveposition-root-not-rootelement/, model );
 	} );
 
 	it( 'should listen to the model applyOperation event', () => {

+ 6 - 6
packages/ckeditor5-engine/tests/model/markercollection.js

@@ -209,7 +209,7 @@ describe( 'MarkerCollection', () => {
 		it( 'should throw if marker does not exist', () => {
 			expectToThrowCKEditorError( () => {
 				markers._refresh( 'name' );
-			}, 'markercollection-refresh-marker-not-exists: Marker with provided name does not exists.', null );
+			}, /^markercollection-refresh-marker-not-exists:/, markers );
 		} );
 	} );
 
@@ -294,23 +294,23 @@ describe( 'Marker', () => {
 
 		expectToThrowCKEditorError( () => {
 			marker.getRange();
-		}, /^marker-destroyed/, null );
+		}, /^marker-destroyed/, model );
 
 		expectToThrowCKEditorError( () => {
 			marker.getStart();
-		}, /^marker-destroyed/, null );
+		}, /^marker-destroyed/, model );
 
 		expectToThrowCKEditorError( () => {
 			marker.getEnd();
-		}, /^marker-destroyed/, null );
+		}, /^marker-destroyed/, model );
 
 		expectToThrowCKEditorError( () => {
 			marker.managedUsingOperations;
-		}, /^marker-destroyed/, null );
+		}, /^marker-destroyed/, model );
 
 		expectToThrowCKEditorError( () => {
 			marker.affectsData;
-		}, /^marker-destroyed/, null );
+		}, /^marker-destroyed/, model );
 	} );
 
 	it( 'should attach live range to marker', () => {

+ 3 - 2
packages/ckeditor5-engine/tests/model/node.js

@@ -9,6 +9,7 @@ import Node from '../../src/model/node';
 import Element from '../../src/model/element';
 import Text from '../../src/model/text';
 import count from '@ckeditor/ckeditor5-utils/src/count';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'Node', () => {
 	let doc, root, node,
@@ -129,7 +130,7 @@ describe( 'Node', () => {
 
 			expectToThrowCKEditorError( () => {
 				node.index;
-			}, /model-node-not-found-in-parent/, null );
+			}, /model-node-not-found-in-parent/, node.parent );
 		} );
 	} );
 
@@ -187,7 +188,7 @@ describe( 'Node', () => {
 
 			expectToThrowCKEditorError( () => {
 				node.startOffset;
-			}, /model-node-not-found-in-parent/, null );
+			}, /model-node-not-found-in-parent/, node.parent );
 		} );
 	} );
 

+ 5 - 5
packages/ckeditor5-engine/tests/model/nodelist.js

@@ -85,11 +85,11 @@ describe( 'NodeList', () => {
 		it( 'should throw if given offset is too high or too low', () => {
 			expectToThrowCKEditorError( () => {
 				nodes.indexToOffset( -1 );
-			}, /model-nodelist-index-out-of-bounds/, null );
+			}, /model-nodelist-index-out-of-bounds/, nodes );
 
 			expectToThrowCKEditorError( () => {
 				nodes.indexToOffset( 99 );
-			}, /model-nodelist-index-out-of-bounds/, null );
+			}, /model-nodelist-index-out-of-bounds/, nodes );
 		} );
 
 		it( 'should return length if given offset is equal to maxOffset', () => {
@@ -109,11 +109,11 @@ describe( 'NodeList', () => {
 		it( 'should throw if given offset is too high or too low', () => {
 			expectToThrowCKEditorError( () => {
 				nodes.offsetToIndex( -1 );
-			}, /nodelist-offset-out-of-bounds/, null );
+			}, /nodelist-offset-out-of-bounds/, nodes );
 
 			expectToThrowCKEditorError( () => {
 				nodes.offsetToIndex( 55 );
-			}, /nodelist-offset-out-of-bounds/, null );
+			}, /nodelist-offset-out-of-bounds/, nodes );
 		} );
 
 		it( 'should return length if given offset is equal to maxOffset', () => {
@@ -160,7 +160,7 @@ describe( 'NodeList', () => {
 		it( 'should throw if not a Node is inserted', () => {
 			expectToThrowCKEditorError( () => {
 				nodes._insertNodes( 0, [ 'foo' ] );
-			}, /nodelist-insertNodes-not-node/, null );
+			}, /nodelist-insertNodes-not-node/, nodes );
 		} );
 	} );
 

+ 1 - 0
packages/ckeditor5-engine/tests/model/operation/detachoperation.js

@@ -9,6 +9,7 @@ import DetachOperation from '../../../src/model/operation/detachoperation';
 import Position from '../../../src/model/position';
 import DocumentFragment from '../../../src/model/documentfragment';
 import Element from '../../../src/model/element';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'DetachOperation', () => {
 	let model, doc, docFrag, element;

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

@@ -10,7 +10,7 @@ import InsertOperation from '../../../src/model/operation/insertoperation';
 import MoveOperation from '../../../src/model/operation/moveoperation';
 import Position from '../../../src/model/position';
 import Text from '../../../src/model/text';
-
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'InsertOperation', () => {
 	let model, doc, root;

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

@@ -9,7 +9,7 @@ import SplitOperation from '../../../src/model/operation/splitoperation';
 import Position from '../../../src/model/position';
 import Element from '../../../src/model/element';
 import Text from '../../../src/model/text';
-
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'MergeOperation', () => {
 	let model, doc, root, gy, gyPos;

+ 4 - 2
packages/ckeditor5-engine/tests/model/operation/moveoperation.js

@@ -212,7 +212,8 @@ describe( 'MoveOperation', () => {
 				doc.version
 			);
 
-			expectToThrowCKEditorError( () => operation._validate(),, model );
+			expect( () => operation._validate() ).not.to.throw();
+		} );
 
 		it( 'should not throw when operation paths looks like incorrect but move is between different roots', () => {
 			const p = new Element( 'p' );
@@ -226,7 +227,8 @@ describe( 'MoveOperation', () => {
 				doc.version
 			);
 
-			expectToThrowCKEditorError( () => operation._validate(),, model );
+			expect( () => operation._validate() ).not.to.throw();
+		} );
 	} );
 
 	it( 'should create MoveOperation with the same parameters when cloned', () => {

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

@@ -7,7 +7,7 @@ import Model from '../../../src/model/model';
 import DocumentFragment from '../../../src/model/documentfragment';
 import Element from '../../../src/model/element';
 import RootAttributeOperation from '../../../src/model/operation/rootattributeoperation';
-
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'RootAttributeOperation', () => {
 	let model, doc, root;

+ 1 - 2
packages/ckeditor5-engine/tests/model/operation/utils.js

@@ -12,8 +12,7 @@ import Position from '../../../src/model/position';
 import Range from '../../../src/model/range';
 import * as utils from '../../../src/model/operation/utils';
 import { getData } from '../../../src/dev-utils/model';
-
-
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 let model, doc, root;
 

+ 14 - 14
packages/ckeditor5-engine/tests/model/position.js

@@ -110,21 +110,21 @@ describe( 'Position', () => {
 		it( 'should throw error if given path is incorrect', () => {
 			expectToThrowCKEditorError( () => {
 				new Position( root, {} ); // eslint-disable-line no-new
-			}, /model-position-path-incorrect/, model );
+			}, /model-position-path-incorrect/, null );
 
 			expectToThrowCKEditorError( () => {
 				new Position( root, [] ); // eslint-disable-line no-new
-			}, /model-position-path-incorrect/, model );
+			}, /model-position-path-incorrect/, null );
 		} );
 
 		it( 'should throw error if given root is invalid', () => {
 			expectToThrowCKEditorError( () => {
 				new Position( new Text( 'a' ) ); // eslint-disable-line no-new
-			}, /model-position-root-invalid/, model );
+			}, /model-position-root-invalid/, null );
 
-			expectToThrowCKEditorError( () => {
+			expect( () => {
 				new Position(); // eslint-disable-line no-new
-			}, model );
+			} ).to.throw();
 		} );
 	} );
 
@@ -889,11 +889,11 @@ describe( 'Position', () => {
 
 		it( 'should not update path if insertion position parent is a node from that path and offset is ' +
 			'after next node on that path', () => {
-				const position = new Position( root, [ 1, 2, 3 ] );
-				const transformed = position._getTransformedByInsertion( new Position( root, [ 1, 3 ] ), 2 );
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position._getTransformedByInsertion( new Position( root, [ 1, 3 ] ), 2 );
 
-				expect( transformed.path ).to.deep.equal( [ 1, 2, 3 ] );
-			} );
+			expect( transformed.path ).to.deep.equal( [ 1, 2, 3 ] );
+		} );
 
 		it( 'should not update if insertion is in different path', () => {
 			const position = new Position( root, [ 1, 1 ] );
@@ -955,12 +955,12 @@ describe( 'Position', () => {
 		} );
 
 		it( 'should not update path if deletion position parent is a node from that path and ' +
-			'offset is after next node on that path', () => {
-				const position = new Position( root, [ 1, 2, 3 ] );
-				const transformed = position._getTransformedByDeletion( new Position( root, [ 1, 3 ] ), 2 );
+		'offset is after next node on that path', () => {
+			const position = new Position( root, [ 1, 2, 3 ] );
+			const transformed = position._getTransformedByDeletion( new Position( root, [ 1, 3 ] ), 2 );
 
-				expect( transformed.path ).to.deep.equal( [ 1, 2, 3 ] );
-			} );
+			expect( transformed.path ).to.deep.equal( [ 1, 2, 3 ] );
+		} );
 	} );
 
 	describe( '_getTransformedByMove()', () => {

+ 27 - 28
packages/ckeditor5-engine/tests/model/schema.js

@@ -5,8 +5,6 @@
 
 import Schema, { SchemaContext } from '../../src/model/schema';
 
-
-
 import Model from '../../src/model/model';
 
 import DocumentFragment from '../../src/model/documentfragment';
@@ -19,6 +17,7 @@ import Range from '../../src/model/range';
 import { getData, setData, stringify, parse } from '../../src/dev-utils/model';
 
 import AttributeOperation from '../../src/model/operation/attributeoperation';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'Schema', () => {
 	let schema, root1, r1p1, r1p2, r1bQ, r1bQp, root2;
@@ -1005,16 +1004,16 @@ describe( 'Schema', () => {
 			setData(
 				model,
 				'<div>' +
-					'<section>' +
-						'<article>' +
-							'<paragraph>[foo]</paragraph>' +
-						'</article>' +
-					'</section>' +
-					'<widget>' +
-						'<image>' +
-							'<caption>b[a]r</caption>' +
-						'</image>' +
-					'</widget>' +
+				'<section>' +
+				'<article>' +
+				'<paragraph>[foo]</paragraph>' +
+				'</article>' +
+				'</section>' +
+				'<widget>' +
+				'<image>' +
+				'<caption>b[a]r</caption>' +
+				'</image>' +
+				'</widget>' +
 				'</div>'
 			);
 
@@ -1026,11 +1025,11 @@ describe( 'Schema', () => {
 			setData(
 				model,
 				'<div>' +
-					'<section>' +
-						'<article>' +
-							'<paragraph>[foo]</paragraph>' +
-						'</article>' +
-					'</section>' +
+				'<section>' +
+				'<article>' +
+				'<paragraph>[foo]</paragraph>' +
+				'</article>' +
+				'</section>' +
 				'</div>' +
 				'<section>b[]ar</section>'
 			);
@@ -1042,10 +1041,10 @@ describe( 'Schema', () => {
 			setData(
 				model,
 				'<image>' +
-					'<caption>[Foo</caption>' +
+				'<caption>[Foo</caption>' +
 				'</image>' +
 				'<article>' +
-					'<paragraph>Paragraph in article]</paragraph>' +
+				'<paragraph>Paragraph in article]</paragraph>' +
 				'</article>' +
 				'<paragraph>Paragraph item 1</paragraph>' +
 				'<paragraph>Paragraph [item 2]</paragraph>'
@@ -1060,10 +1059,10 @@ describe( 'Schema', () => {
 				'<paragraph>Paragraph item 1</paragraph>' +
 				'<paragraph>Paragraph [item 2]</paragraph>' +
 				'<image>' +
-					'<caption>[Foo</caption>' +
+				'<caption>[Foo</caption>' +
 				'</image>' +
 				'<article>' +
-					'<paragraph>Paragraph in article]</paragraph>' +
+				'<paragraph>Paragraph in article]</paragraph>' +
 				'</article>'
 			);
 
@@ -1814,12 +1813,12 @@ describe( 'Schema', () => {
 				expect( getData( model, { withoutSelection: true } ) )
 					.to.equal(
 						'<div>' +
-							'<paragraph>' +
-								'<$text b="1">foo</$text>' +
-								'<image b="1"></image>' +
-							'</paragraph>' +
-							'<$text a="1">bar</$text>' +
-							'<image a="1"></image>' +
+						'<paragraph>' +
+						'<$text b="1">foo</$text>' +
+						'<image b="1"></image>' +
+						'</paragraph>' +
+						'<$text a="1">bar</$text>' +
+						'<image a="1"></image>' +
 						'</div>'
 					);
 			} );
@@ -2139,7 +2138,7 @@ describe( 'Schema', () => {
 			} );
 
 			it( 'passes $root>paragraph and $root2>paragraph – where $root2 inherits content of $root' +
-				'and paragraph inherits allowWhere from $block', () => {
+			'and paragraph inherits allowWhere from $block', () => {
 				schema.register( '$root' );
 				schema.register( '$root2', {
 					allowContentOf: '$root'

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

@@ -123,7 +123,7 @@ describe( 'Selection', () => {
 			expectToThrowCKEditorError( () => {
 				// eslint-disable-next-line no-new
 				new Selection( {} );
-			} ).to.throw( /model-selection-setTo-not-selectable/ );
+			}, /model-selection-setTo-not-selectable/ );
 		} );
 	} );
 
@@ -282,13 +282,13 @@ describe( 'Selection', () => {
 		it( 'should throw an error when trying to set selection to not selectable', () => {
 			expectToThrowCKEditorError( () => {
 				selection.setTo( {} );
-			} ).to.throw( /model-selection-setTo-not-selectable/ );
+			}, /model-selection-setTo-not-selectable/ );
 		} );
 
 		it( 'should throw an error when trying to set selection to not selectable #2', () => {
 			expectToThrowCKEditorError( () => {
 				selection.setTo();
-			} ).to.throw( /model-selection-setTo-not-selectable/ );
+			}, /model-selection-setTo-not-selectable/ );
 		} );
 
 		it( 'should allow setting selection inside an element', () => {