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

Commit

Permalink
Merge branch t/ckeditor5-watchdog/1
Browse files Browse the repository at this point in the history
Internal: Add context to CKEditorError exceptions. Required by ckeditor/ckeditor5-watchdog#2.
  • Loading branch information
Piotr Jasiun committed Jul 2, 2019
2 parents 946e762 + e8d7d1b commit acffed3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
10 changes: 8 additions & 2 deletions src/mentioncommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ export default class MentionCommand extends Command {
*
* @error mentioncommand-incorrect-marker
*/
throw new CKEditorError( 'mentioncommand-incorrect-marker: The marker must be a single character.' );
throw new CKEditorError(
'mentioncommand-incorrect-marker: The marker must be a single character.',
this
);
}

if ( mentionID.charAt( 0 ) != options.marker ) {
Expand Down Expand Up @@ -127,7 +130,10 @@ export default class MentionCommand extends Command {
*
* @error mentioncommand-incorrect-id
*/
throw new CKEditorError( 'mentioncommand-incorrect-id: The item id must start with the marker character.' );
throw new CKEditorError(
'mentioncommand-incorrect-id: The item id must start with the marker character.',
this
);
}

model.change( writer => {
Expand Down
5 changes: 4 additions & 1 deletion src/mentionui.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ export default class MentionUI extends Plugin {
*
* @error mentionconfig-incorrect-marker
*/
throw new CKEditorError( 'mentionconfig-incorrect-marker: The marker must be provided and it must be a single character.' );
throw new CKEditorError(
'mentionconfig-incorrect-marker: The marker must be provided and it must be a single character.',
null
);
}

const minimumCharacters = mentionDescription.minimumCharacters || 0;
Expand Down
7 changes: 4 additions & 3 deletions tests/mentioncommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltestedit
import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';

import MentionCommand from '../src/mentioncommand';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';

import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';

describe( 'MentionCommand', () => {
let editor, command, model, doc, selection;
Expand Down Expand Up @@ -145,7 +146,7 @@ describe( 'MentionCommand', () => {
];

for ( const options of testCases ) {
expect( () => command.execute( options ) ).to.throw( CKEditorError, /mentioncommand-incorrect-marker/ );
expectToThrowCKEditorError( () => command.execute( options ), /mentioncommand-incorrect-marker/, editor );
}
} );

Expand All @@ -159,7 +160,7 @@ describe( 'MentionCommand', () => {
];

for ( const options of testCases ) {
expect( () => command.execute( options ) ).to.throw( CKEditorError, /mentioncommand-incorrect-id/ );
expectToThrowCKEditorError( () => command.execute( options ), /mentioncommand-incorrect-id/, editor );
}
} );
} );
Expand Down
11 changes: 4 additions & 7 deletions tests/mentionui.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import global from '@ckeditor/ckeditor5-utils/src/dom/global';
import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventdata';
import EventInfo from '@ckeditor/ckeditor5-utils/src/eventinfo';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
import env from '@ckeditor/ckeditor5-utils/src/env';

import MentionUI, { createRegExp } from '../src/mentionui';
import featureDetection from '../src/featuredetection';
import MentionEditing from '../src/mentionediting';
import MentionsView from '../src/ui/mentionsview';
import { assertCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';

describe( 'MentionUI', () => {
let editor, model, doc, editingView, mentionUI, editorElement, mentionsView, panelView;
Expand Down Expand Up @@ -67,22 +67,19 @@ describe( 'MentionUI', () => {
describe( 'init()', () => {
it( 'should throw if marker was not provided for feed', () => {
return createClassicTestEditor( { feeds: [ { feed: [ 'a' ] } ] } ).catch( error => {
expect( error ).to.be.instanceOf( CKEditorError );
expect( error.message ).to.match( /mentionconfig-incorrect-marker/ );
assertCKEditorError( error, /mentionconfig-incorrect-marker/, null );
} );
} );

it( 'should throw if marker is empty string', () => {
return createClassicTestEditor( { feeds: [ { marker: '', feed: [ 'a' ] } ] } ).catch( error => {
expect( error ).to.be.instanceOf( CKEditorError );
expect( error.message ).to.match( /mentionconfig-incorrect-marker/ );
assertCKEditorError( error, /mentionconfig-incorrect-marker/, null );
} );
} );

it( 'should throw if marker is longer then 1 character', () => {
return createClassicTestEditor( { feeds: [ { marker: '$$', feed: [ 'a' ] } ] } ).catch( error => {
expect( error ).to.be.instanceOf( CKEditorError );
expect( error.message ).to.match( /mentionconfig-incorrect-marker/ );
assertCKEditorError( error, /mentionconfig-incorrect-marker/, null );
} );
} );
} );
Expand Down

0 comments on commit acffed3

Please sign in to comment.