浏览代码

transaction-register-taken error.

Piotr Jasiun 10 年之前
父节点
当前提交
370a3bd6d0

+ 10 - 2
packages/ckeditor5-engine/src/document/deltas/transaction-base.js

@@ -5,7 +5,7 @@
 
 'use strict';
 
-CKEDITOR.define( [], () => {
+CKEDITOR.define( [ 'ckeditorerror' ], ( CKEditorError ) => {
 	/**
 	 * @class document.Transaction
 	 */
@@ -31,7 +31,15 @@ CKEDITOR.define( [], () => {
 
 		static register( name, creator ) {
 			if ( Transaction.prototype[ name ] ) {
-				throw 'error';
+				/**
+				 * This transaction method is already taken.
+				 *
+				 * @error transaction-register-taken
+				 * @param {String} name
+				 */
+				throw new CKEditorError(
+					'transaction-register-taken: This transaction method is already taken.',
+					{ name: name } );
 			}
 
 			Transaction.prototype[ name ] = function() {

+ 13 - 3
packages/ckeditor5-engine/tests/document/transaction.js

@@ -9,14 +9,16 @@
 
 var modules = bender.amd.require(
 	'document/transaction',
-	'document/deltas/delta' );
+	'document/deltas/delta',
+	'ckeditorerror' );
 
 describe( 'Transaction', () => {
-	var Transaction, Delta;
+	var Transaction, Delta, CKEditorError;
 
 	before( () => {
 		Transaction = modules[ 'document/transaction' ];
 		Delta = modules[ 'document/deltas/delta' ];
+		CKEditorError = modules.ckeditorerror;
 	} );
 
 	it( 'should have registered basic methods', () => {
@@ -75,7 +77,7 @@ describe( 'Transaction', () => {
 
 			var transaction = new Transaction( doc );
 
-			var stub = sinon.stub().returns( new TestDelta( transaction ) );
+			var stub = sinon.stub();
 
 			Transaction.register( 'foo', stub );
 
@@ -83,5 +85,13 @@ describe( 'Transaction', () => {
 
 			sinon.assert.calledWith( stub, doc, transaction, arg );
 		} );
+
+		it( 'should throw if one try to register the same transaction twice', () => {
+			Transaction.register( 'foo', () => {} );
+
+			expect( () => {
+				Transaction.register( 'foo', () => {} );
+			} ).to.throw( CKEditorError, /^transaction-register-taken/ );
+		} );
 	} );
 } );