Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it( 'should throw for a non-flat range', () => {
root._insertChild( 0, [
new Element( 'paragraph', null, new Text( 'Foo' ) ),
new Element( 'paragraph', null, new Text( 'Bar' ) )
] );
expectToThrowCKEditorError( () => {
const operation = new AttributeOperation(
new Range( new Position( root, [ 0, 1 ] ), new Position( root, [ 1, 1 ] ) ),
'x',
null,
2,
doc.version
);
operation._validate();
}, /attribute-operation-range-not-flat/, model );
} );
} );
it( 'should throw if element to unwrap has no parent', () => {
const element = new Element( 'p' );
expectToThrowCKEditorError( () => {
unwrap( element );
}, /^writer-unwrap-element-no-parent/, model );
} );
it( 'should throw when moving element from document to document fragment', () => {
const root = doc.createRoot();
const docFrag = createDocumentFragment();
const node = createText( 'foo' );
insert( node, root );
expectToThrowCKEditorError( () => {
insert( node, docFrag );
}, /^model-writer-insert-forbidden-move/, model );
} );
it( 'should throw if given offset is too high or too low', () => {
expectToThrowCKEditorError( () => {
nodes.offsetToIndex( -1 );
}, /nodelist-offset-out-of-bounds/, nodes );
expectToThrowCKEditorError( () => {
nodes.offsetToIndex( 55 );
}, /nodelist-offset-out-of-bounds/, nodes );
} );
it( 'should throw an error if split position is invalid', () => {
const p1 = new Element( 'p1', null, new Text( 'Foobar' ) );
root._insertChild( 0, [ p1 ] );
const operation = new SplitOperation( new Position( root, [ 0, 8 ] ), 3, null, doc.version );
expectToThrowCKEditorError( () => operation._validate(), /split-operation-position-invalid/, model );
} );
it( 'should throw an error when is used with editor without `ElementApiMixin`', () => {
const editor = new Editor();
expectToThrowCKEditorError( () => {
attachToForm( editor );
}, /^attachtoform-missing-elementapi-interface/, editor );
} );
it( 'should throw an error when trying to set to not selectable', () => {
const otherSelection = new DocumentSelection();
expectToThrowCKEditorError( () => {
otherSelection._setTo( {} );
}, /view-selection-setTo-not-selectable/ );
} );
it( 'should throw if not an Element instance is passed', () => {
expectToThrowCKEditorError( () => {
rename( new Text( 'abc' ), 'h' );
}, /^writer-rename-not-element-instance/, model );
} );
it( 'should throw an error when the second parameter is not passed and first is an item', () => {
const foo = new Text( 'foo' );
expectToThrowCKEditorError( () => {
documentSelection._setTo( foo );
}, /view-selection-setTo-required-second-parameter/, documentSelection );
} );
it( 'should throw an error if split position is in root', () => {
const p1 = new Element( 'p1', null, new Text( 'Foobar' ) );
root._insertChild( 0, [ p1 ] );
const operation = new SplitOperation( new Position( root, [ 0, 0 ] ), 3, null, doc.version );
operation.splitPosition = new Position( root, [ 1 ] );
expectToThrowCKEditorError( () => operation._validate(), /split-operation-split-in-root/, model );
} );