8
0
Просмотр исходного кода

Merge branch t/ckeditor5-watchdog/1

Internal: Add context to CKEditorError exceptions. Required by ckeditor/ckeditor5-watchdog#2.
Piotr Jasiun 6 лет назад
Родитель
Сommit
03a77b4de9

+ 8 - 2
packages/ckeditor5-mention/src/mentioncommand.js

@@ -98,7 +98,10 @@ export default class MentionCommand extends Command {
 			 *
 			 *
 			 * @error mentioncommand-incorrect-marker
 			 * @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 ) {
 		if ( mentionID.charAt( 0 ) != options.marker ) {
@@ -127,7 +130,10 @@ export default class MentionCommand extends Command {
 			 *
 			 *
 			 * @error mentioncommand-incorrect-id
 			 * @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 => {
 		model.change( writer => {

+ 4 - 1
packages/ckeditor5-mention/src/mentionui.js

@@ -128,7 +128,10 @@ export default class MentionUI extends Plugin {
 				 *
 				 *
 				 * @error mentionconfig-incorrect-marker
 				 * @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;
 			const minimumCharacters = mentionDescription.minimumCharacters || 0;

+ 4 - 3
packages/ckeditor5-mention/tests/mentioncommand.js

@@ -7,7 +7,8 @@ import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltestedit
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 
 import MentionCommand from '../src/mentioncommand';
 import MentionCommand from '../src/mentioncommand';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 
 describe( 'MentionCommand', () => {
 describe( 'MentionCommand', () => {
 	let editor, command, model, doc, selection;
 	let editor, command, model, doc, selection;
@@ -145,7 +146,7 @@ describe( 'MentionCommand', () => {
 			];
 			];
 
 
 			for ( const options of testCases ) {
 			for ( const options of testCases ) {
-				expect( () => command.execute( options ) ).to.throw( CKEditorError, /mentioncommand-incorrect-marker/ );
+				expectToThrowCKEditorError( () => command.execute( options ), /mentioncommand-incorrect-marker/, editor );
 			}
 			}
 		} );
 		} );
 
 
@@ -159,7 +160,7 @@ describe( 'MentionCommand', () => {
 			];
 			];
 
 
 			for ( const options of testCases ) {
 			for ( const options of testCases ) {
-				expect( () => command.execute( options ) ).to.throw( CKEditorError, /mentioncommand-incorrect-id/ );
+				expectToThrowCKEditorError( () => command.execute( options ), /mentioncommand-incorrect-id/, editor );
 			}
 			}
 		} );
 		} );
 	} );
 	} );

+ 4 - 7
packages/ckeditor5-mention/tests/mentionui.js

@@ -14,7 +14,6 @@ import global from '@ckeditor/ckeditor5-utils/src/dom/global';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventdata';
 import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventdata';
 import EventInfo from '@ckeditor/ckeditor5-utils/src/eventinfo';
 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 ContextualBalloon from '@ckeditor/ckeditor5-ui/src/panel/balloon/contextualballoon';
 import env from '@ckeditor/ckeditor5-utils/src/env';
 import env from '@ckeditor/ckeditor5-utils/src/env';
 
 
@@ -22,6 +21,7 @@ import MentionUI, { createRegExp } from '../src/mentionui';
 import featureDetection from '../src/featuredetection';
 import featureDetection from '../src/featuredetection';
 import MentionEditing from '../src/mentionediting';
 import MentionEditing from '../src/mentionediting';
 import MentionsView from '../src/ui/mentionsview';
 import MentionsView from '../src/ui/mentionsview';
+import { assertCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 
 describe( 'MentionUI', () => {
 describe( 'MentionUI', () => {
 	let editor, model, doc, editingView, mentionUI, editorElement, mentionsView, panelView;
 	let editor, model, doc, editingView, mentionUI, editorElement, mentionsView, panelView;
@@ -67,22 +67,19 @@ describe( 'MentionUI', () => {
 	describe( 'init()', () => {
 	describe( 'init()', () => {
 		it( 'should throw if marker was not provided for feed', () => {
 		it( 'should throw if marker was not provided for feed', () => {
 			return createClassicTestEditor( { feeds: [ { feed: [ 'a' ] } ] } ).catch( error => {
 			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', () => {
 		it( 'should throw if marker is empty string', () => {
 			return createClassicTestEditor( { feeds: [ { marker: '', feed: [ 'a' ] } ] } ).catch( error => {
 			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', () => {
 		it( 'should throw if marker is longer then 1 character', () => {
 			return createClassicTestEditor( { feeds: [ { marker: '$$', feed: [ 'a' ] } ] } ).catch( error => {
 			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 );
 			} );
 			} );
 		} );
 		} );
 	} );
 	} );