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

Commit

Permalink
Throw error when trying to add an alias for not registered dispatcher.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodator committed Feb 7, 2019
1 parent e9a28e9 commit 9076ac9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/conversion/conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,17 @@ export default class Conversion {
addAlias( alias, dispatcher ) {
const groupEntry = [ ...this._groups.entries() ].find( ( [ , dispatchers ] ) => dispatchers.includes( dispatcher ) );

const groupName = groupEntry ? groupEntry[ 0 ] : null;
if ( !groupEntry ) {
/**
* Trying to register and alias for a dispatcher that nas not been registered.
*
* @error conversion-add-alias-dispatcher-not-registered
*/
throw new CKEditorError( 'conversion-add-alias-dispatcher-not-registered: ' +
'Trying to register and alias for a dispatcher that nas not been registered.' );
}

const groupName = groupEntry[ 0 ];

const helper = this._helpers.get( groupName );

Expand All @@ -97,7 +107,7 @@ export default class Conversion {
/**
* Trying to register a group name that has already been registered.
*
* @error conversion-register-group-exists
* @error conversion-group-exists
*/
throw new CKEditorError( 'conversion-group-exists: Trying to register a group name that has already been registered.' );
}
Expand Down
6 changes: 6 additions & 0 deletions tests/conversion/conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ describe( 'Conversion', () => {
conversion.addAlias( 'upcast', upcastDispaA );
} ).to.throw( CKEditorError, /conversion-group-exists/ );
} );

it( 'should throw when trying to add not registered dispatcher', () => {
expect( () => {
conversion.addAlias( 'foo', {} );
} ).to.throw( CKEditorError, /conversion-add-alias-dispatcher-not-registered/ );
} );
} );

describe( 'for()', () => {
Expand Down

0 comments on commit 9076ac9

Please sign in to comment.