瀏覽代碼

Merge pull request #65 from ckeditor/t/64

Updated tests with `throwCKEditorError` check.
Piotrek Koszuliński 9 年之前
父節點
當前提交
6dd116d8aa

+ 6 - 7
packages/ckeditor5-utils/tests/collection.js

@@ -5,7 +5,6 @@
 
 import testUtils from '/tests/core/_utils/utils.js';
 import Collection from '/ckeditor5/utils/collection.js';
-import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
 
 testUtils.createSinonSandbox();
 
@@ -125,7 +124,7 @@ describe( 'Collection', () => {
 
 			expect( () => {
 				collection.add( item2 );
-			} ).to.throw( CKEditorError, /^collection-add-item-already-exists/ );
+			} ).to.throwCKEditorError( /^collection-add-item-already-exists/ );
 		} );
 
 		it( 'should throw when item\'s id is not a string', () => {
@@ -133,7 +132,7 @@ describe( 'Collection', () => {
 
 			expect( () => {
 				collection.add( item );
-			} ).to.throw( CKEditorError, /^collection-add-invalid-id/ );
+			} ).to.throwCKEditorError( /^collection-add-invalid-id/ );
 		} );
 
 		it(
@@ -295,7 +294,7 @@ describe( 'Collection', () => {
 		it( 'should throw if neither string or number given', () => {
 			expect( () => {
 				collection.get( true );
-			} ).to.throw( CKEditorError, /^collection-get-invalid-arg/ );
+			} ).to.throwCKEditorError( /^collection-get-invalid-arg/ );
 		} );
 	} );
 
@@ -400,7 +399,7 @@ describe( 'Collection', () => {
 
 			expect( () => {
 				collection.remove( 1 );
-			} ).to.throw( CKEditorError, /^collection-remove-404/ );
+			} ).to.throwCKEditorError( /^collection-remove-404/ );
 
 			expect( collection ).to.have.length( 1 );
 		} );
@@ -410,7 +409,7 @@ describe( 'Collection', () => {
 
 			expect( () => {
 				collection.remove( 'bar' );
-			} ).to.throw( CKEditorError, /^collection-remove-404/ );
+			} ).to.throwCKEditorError( /^collection-remove-404/ );
 
 			expect( collection ).to.have.length( 1 );
 		} );
@@ -420,7 +419,7 @@ describe( 'Collection', () => {
 
 			expect( () => {
 				collection.remove( getItem( 'bar' ) );
-			} ).to.throw( CKEditorError, /^collection-remove-404/ );
+			} ).to.throwCKEditorError( /^collection-remove-404/ );
 
 			expect( collection ).to.have.length( 1 );
 		} );

+ 2 - 3
packages/ckeditor5-utils/tests/keyboard.js

@@ -4,7 +4,6 @@
  */
 
 import { keyCodes, getCode, parseKeystroke } from '/ckeditor5/utils/keyboard.js';
-import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
 
 describe( 'Keyboard', () => {
 	describe( 'keyCodes', () => {
@@ -43,7 +42,7 @@ describe( 'Keyboard', () => {
 		it( 'throws when passed unknown key name', () => {
 			expect( () => {
 				getCode( 'foo' );
-			} ).to.throw( CKEditorError, /^keyboard-unknown-key:/ );
+			} ).to.throwCKEditorError( /^keyboard-unknown-key:/ );
 		} );
 
 		it( 'gets code of a keystroke info', () => {
@@ -84,7 +83,7 @@ describe( 'Keyboard', () => {
 		it( 'throws on unknown name', () => {
 			expect( () => {
 				parseKeystroke( 'foo' );
-			} ).to.throw( CKEditorError, /^keyboard-unknown-key:/ );
+			} ).to.throwCKEditorError( /^keyboard-unknown-key:/ );
 		} );
 	} );
 } );

+ 22 - 23
packages/ckeditor5-utils/tests/observablemixin.js

@@ -8,7 +8,6 @@ import utilsTestUtils from '/tests/utils/_utils/utils.js';
 import ObservableMixin from '/ckeditor5/utils/observablemixin.js';
 import EmitterMixin from '/ckeditor5/utils/emittermixin.js';
 import EventInfo from '/ckeditor5/utils/eventinfo.js';
-import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
 import mix from '/ckeditor5/utils/mix.js';
 
 const assertBinding = utilsTestUtils.assertBinding;
@@ -146,7 +145,7 @@ describe( 'Observable', () => {
 
 			expect( () => {
 				car.set( 'normalProperty', 2 );
-			} ).to.throw( CKEditorError, /^observable-set-cannot-override/ );
+			} ).to.throwCKEditorError( /^observable-set-cannot-override/ );
 
 			expect( car ).to.have.property( 'normalProperty', 1 );
 		} );
@@ -160,7 +159,7 @@ describe( 'Observable', () => {
 
 			expect( () => {
 				car.set( 'method', 2 );
-			} ).to.throw( CKEditorError, /^observable-set-cannot-override/ );
+			} ).to.throwCKEditorError( /^observable-set-cannot-override/ );
 
 			expect( car.method ).to.be.a( 'function' );
 		} );
@@ -198,28 +197,28 @@ describe( 'Observable', () => {
 		it( 'should throw when attributes are not strings', () => {
 			expect( () => {
 				car.bind();
-			} ).to.throw( CKEditorError, /observable-bind-wrong-attrs/ );
+			} ).to.throwCKEditorError( /observable-bind-wrong-attrs/ );
 
 			expect( () => {
 				car.bind( new Date() );
-			} ).to.throw( CKEditorError, /observable-bind-wrong-attrs/ );
+			} ).to.throwCKEditorError( /observable-bind-wrong-attrs/ );
 
 			expect( () => {
 				car.bind( 'color', new Date() );
-			} ).to.throw( CKEditorError, /observable-bind-wrong-attrs/ );
+			} ).to.throwCKEditorError( /observable-bind-wrong-attrs/ );
 		} );
 
 		it( 'should throw when the same attribute is used than once', () => {
 			expect( () => {
 				car.bind( 'color', 'color' );
-			} ).to.throw( CKEditorError, /observable-bind-duplicate-attrs/ );
+			} ).to.throwCKEditorError( /observable-bind-duplicate-attrs/ );
 		} );
 
 		it( 'should throw when binding the same attribute more than once', () => {
 			expect( () => {
 				car.bind( 'color' );
 				car.bind( 'color' );
-			} ).to.throw( CKEditorError, /observable-bind-rebind/ );
+			} ).to.throwCKEditorError( /observable-bind-rebind/ );
 		} );
 
 		describe( 'to', () => {
@@ -234,7 +233,7 @@ describe( 'Observable', () => {
 					car = new Car();
 
 					car.bind( 'color' ).to();
-				} ).to.throw( CKEditorError, /observable-bind-to-parse-error/ );
+				} ).to.throwCKEditorError( /observable-bind-to-parse-error/ );
 			} );
 
 			it( 'should throw when binding multiple attributes to multiple observables', () => {
@@ -244,31 +243,31 @@ describe( 'Observable', () => {
 
 				expect( () => {
 					vehicle.bind( 'color', 'year' ).to( car1, 'color', car2, 'year' );
-				} ).to.throw( CKEditorError, /observable-bind-to-no-callback/ );
+				} ).to.throwCKEditorError( /observable-bind-to-no-callback/ );
 
 				expect( () => {
 					vehicle = new Car();
 
 					vehicle.bind( 'color', 'year' ).to( car1, car2 );
-				} ).to.throw( CKEditorError, /observable-bind-to-no-callback/ );
+				} ).to.throwCKEditorError( /observable-bind-to-no-callback/ );
 
 				expect( () => {
 					vehicle = new Car();
 
 					vehicle.bind( 'color', 'year' ).to( car1, car2, 'year' );
-				} ).to.throw( CKEditorError, /observable-bind-to-no-callback/ );
+				} ).to.throwCKEditorError( /observable-bind-to-no-callback/ );
 
 				expect( () => {
 					vehicle = new Car();
 
 					vehicle.bind( 'color', 'year' ).to( car1, 'color', car2 );
-				} ).to.throw( CKEditorError, /observable-bind-to-no-callback/ );
+				} ).to.throwCKEditorError( /observable-bind-to-no-callback/ );
 
 				expect( () => {
 					vehicle = new Car();
 
 					vehicle.bind( 'color', 'year', 'custom' ).to( car, car );
-				} ).to.throw( CKEditorError, /observable-bind-to-no-callback/ );
+				} ).to.throwCKEditorError( /observable-bind-to-no-callback/ );
 			} );
 
 			it( 'should throw when binding multiple attributes but passed a callback', () => {
@@ -276,13 +275,13 @@ describe( 'Observable', () => {
 
 				expect( () => {
 					vehicle.bind( 'color', 'year' ).to( car, () => {} );
-				} ).to.throw( CKEditorError, /observable-bind-to-extra-callback/ );
+				} ).to.throwCKEditorError( /observable-bind-to-extra-callback/ );
 
 				expect( () => {
 					vehicle = new Car();
 
 					vehicle.bind( 'color', 'year' ).to( car, car, () => {} );
-				} ).to.throw( CKEditorError, /observable-bind-to-extra-callback/ );
+				} ).to.throwCKEditorError( /observable-bind-to-extra-callback/ );
 			} );
 
 			it( 'should throw when binding a single attribute but multiple callbacks', () => {
@@ -290,13 +289,13 @@ describe( 'Observable', () => {
 
 				expect( () => {
 					vehicle.bind( 'color' ).to( car, () => {}, () => {} );
-				} ).to.throw( CKEditorError, /observable-bind-to-parse-error/ );
+				} ).to.throwCKEditorError( /observable-bind-to-parse-error/ );
 
 				expect( () => {
 					vehicle = new Car();
 
 					vehicle.bind( 'color' ).to( car, car, () => {}, () => {} );
-				} ).to.throw( CKEditorError, /observable-bind-to-parse-error/ );
+				} ).to.throwCKEditorError( /observable-bind-to-parse-error/ );
 			} );
 
 			it( 'should throw when a number of attributes does not match', () => {
@@ -304,25 +303,25 @@ describe( 'Observable', () => {
 
 				expect( () => {
 					vehicle.bind( 'color' ).to( car, 'color', 'year' );
-				} ).to.throw( CKEditorError, /observable-bind-to-attrs-length/ );
+				} ).to.throwCKEditorError( /observable-bind-to-attrs-length/ );
 
 				expect( () => {
 					vehicle = new Car();
 
 					vehicle.bind( 'color', 'year' ).to( car, 'color' );
-				} ).to.throw( CKEditorError, /observable-bind-to-attrs-length/ );
+				} ).to.throwCKEditorError( /observable-bind-to-attrs-length/ );
 
 				expect( () => {
 					vehicle = new Car();
 
 					vehicle.bind( 'color' ).to( car, 'color', 'year', () => {} );
-				} ).to.throw( CKEditorError, /observable-bind-to-attrs-length/ );
+				} ).to.throwCKEditorError( /observable-bind-to-attrs-length/ );
 
 				expect( () => {
 					vehicle = new Car();
 
 					vehicle.bind( 'color' ).to( car, 'color', car, 'color', 'year', () => {} );
-				} ).to.throw( CKEditorError, /observable-bind-to-attrs-length/ );
+				} ).to.throwCKEditorError( /observable-bind-to-attrs-length/ );
 			} );
 
 			it( 'should work when attributes don\'t exist in to() observable #1', () => {
@@ -739,7 +738,7 @@ describe( 'Observable', () => {
 		it( 'should throw when non-string attribute is passed', () => {
 			expect( () => {
 				car.unbind( new Date() );
-			} ).to.throw( CKEditorError, /observable-unbind-wrong-attrs/ );
+			} ).to.throwCKEditorError( /observable-unbind-wrong-attrs/ );
 		} );
 
 		it( 'should remove all bindings', () => {