Kaynağa Gözat

WIP - changing errors.

Maciej Bukowski 6 yıl önce
ebeveyn
işleme
26f76c1055

+ 8 - 7
packages/ckeditor5-ui/tests/componentfactory.js

@@ -5,7 +5,8 @@
 
 import Editor from '@ckeditor/ckeditor5-core/src/editor/editor';
 import ComponentFactory from '../src/componentfactory';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'ComponentFactory', () => {
 	let editor, factory;
@@ -41,17 +42,17 @@ describe( 'ComponentFactory', () => {
 		it( 'throws when trying to override already registered component', () => {
 			factory.add( 'foo', () => {} );
 
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				factory.add( 'foo', () => {} );
-			} ).to.throw( CKEditorError, /^componentfactory-item-exists/ );
+			}, /^componentfactory-item-exists/, editor );
 		} );
 
 		it( 'throws when trying to override already registered component added with different case', () => {
 			factory.add( 'Foo', () => {} );
 
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				factory.add( 'foo', () => {} );
-			} ).to.throw( CKEditorError, /^componentfactory-item-exists/ );
+			}, /^componentfactory-item-exists/, editor );
 		} );
 
 		it( 'does not normalize component names', () => {
@@ -63,9 +64,9 @@ describe( 'ComponentFactory', () => {
 
 	describe( 'create()', () => {
 		it( 'throws when trying to create a component which has not been registered', () => {
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				factory.create( 'foo' );
-			} ).to.throw( CKEditorError, /^componentfactory-item-missing/ );
+			}, /^componentfactory-item-missing/, editor );
 		} );
 
 		it( 'creates an instance', () => {

+ 1 - 3
packages/ckeditor5-ui/tests/dropdown/utils.js

@@ -5,7 +5,7 @@
 
 /* globals document Event */
 
-import utilsTestUtils from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
+import { assertBinding } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
 import Collection from '@ckeditor/ckeditor5-utils/src/collection';
 
@@ -23,8 +23,6 @@ import ListItemView from '../../src/list/listitemview';
 import ListSeparatorView from '../../src/list/listseparatorview';
 import ListView from '../../src/list/listview';
 
-const assertBinding = utilsTestUtils.assertBinding;
-
 describe( 'utils', () => {
 	let locale, dropdownView;
 

+ 17 - 16
packages/ckeditor5-ui/tests/panel/balloon/contextualballoon.js

@@ -7,12 +7,13 @@ import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictest
 import ContextualBalloon from '../../../src/panel/balloon/contextualballoon';
 import BalloonPanelView from '../../../src/panel/balloon/balloonpanelview';
 import View from '../../../src/view';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 import { add as addTranslations, _clear as clearTranslations } from '@ckeditor/ckeditor5-utils/src/translation-service';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 /* global document, Event */
 
@@ -238,7 +239,7 @@ describe( 'ContextualBalloon', () => {
 		} );
 
 		it( 'should throw an error when try to add the same view more than once', () => {
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				balloon.add( {
 					view: viewA,
 					position: {
@@ -246,7 +247,7 @@ describe( 'ContextualBalloon', () => {
 						limiter: balloon.positionLimiter
 					}
 				} );
-			} ).to.throw( CKEditorError, /^contextualballoon-add-view-exist/ );
+			}, /^contextualballoon-add-view-exist/, editor );
 		} );
 
 		it( 'should use a provided limiter instead of #positionLimiter', () => {
@@ -453,15 +454,15 @@ describe( 'ContextualBalloon', () => {
 		} );
 
 		it( 'should do nothing when given stack is already visible', () => {
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				balloon.showStack( 'main' );
 			} ).to.not.throw();
 		} );
 
 		it( 'should throw an error when there is no stack of given id', () => {
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				balloon.showStack( 'second' );
-			} ).to.throw( CKEditorError, 'contextualballoon-showstack-stack-not-exist: Cannot show not existing stack.' );
+			}, 'contextualballoon-showstack-stack-not-exist: Cannot show not existing stack.', editor );
 		} );
 	} );
 
@@ -489,7 +490,7 @@ describe( 'ContextualBalloon', () => {
 			balloon.remove( viewB );
 
 			expect( balloon.visibleView ).to.equal( viewA );
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				balloon.showStack( 'second' );
 			} ).to.not.throw();
 		} );
@@ -503,7 +504,7 @@ describe( 'ContextualBalloon', () => {
 			balloon.remove( viewB );
 
 			expect( balloon.visibleView ).to.equal( viewA );
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				balloon.showStack( 'second' );
 			} ).to.throw();
 		} );
@@ -517,7 +518,7 @@ describe( 'ContextualBalloon', () => {
 			balloon.remove( viewA );
 
 			expect( balloon.visibleView ).to.equal( viewB );
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				balloon.showStack( 'main' );
 			} ).to.throw();
 		} );
@@ -573,7 +574,7 @@ describe( 'ContextualBalloon', () => {
 			expect( balloon.hasView( viewC ) ).to.true;
 
 			// Does not throw, so the stack is there.
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				balloon.showStack( 'second' );
 			} ).to.not.throw();
 		} );
@@ -592,15 +593,15 @@ describe( 'ContextualBalloon', () => {
 			expect( balloon.hasView( viewB ) ).to.false;
 
 			// Does throw, so the stack is not there.
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				balloon.showStack( 'second' );
 			} ).to.throw();
 		} );
 
 		it( 'should throw an error when there is no given view in the stack', () => {
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				balloon.remove( viewB );
-			} ).to.throw( CKEditorError, /^contextualballoon-remove-view-not-exist/ );
+			}, /^contextualballoon-remove-view-not-exist/, editor );
 		} );
 
 		it( 'should set additional css class of visible view to BalloonPanelView', () => {
@@ -707,15 +708,15 @@ describe( 'ContextualBalloon', () => {
 		} );
 
 		it( 'should throw an error when there is no given view in the stack', () => {
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				balloon.remove( viewB );
-			} ).to.throw( CKEditorError, /^contextualballoon-remove-view-not-exist/ );
+			}, /^contextualballoon-remove-view-not-exist/, editor );
 		} );
 	} );
 
 	describe( 'destroy()', () => {
 		it( 'can be called multiple times', () => {
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				balloon.destroy();
 				balloon.destroy();
 			} ).to.not.throw();

+ 18 - 18
packages/ckeditor5-ui/tests/template.js

@@ -10,7 +10,7 @@ import { default as Template, TemplateToBinding, TemplateIfBinding } from '../sr
 import View from '../src/view';
 import ViewCollection from '../src/viewcollection';
 import Model from '../src/model';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+
 import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
 import DomEmitterMixin from '@ckeditor/ckeditor5-utils/src/dom/emittermixin';
 import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
@@ -142,16 +142,16 @@ describe( 'Template', () => {
 
 	describe( 'render()', () => {
 		it( 'throws when the template definition is wrong', () => {
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				new Template( {} ).render();
-			} ).to.throw( CKEditorError, /ui-template-wrong-syntax/ );
+			}, /ui-template-wrong-syntax/ );
 
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				new Template( {
 					tag: 'p',
 					text: 'foo'
 				} ).render();
-			} ).to.throw( CKEditorError, /ui-template-wrong-syntax/ );
+			}, /ui-template-wrong-syntax/ );
 		} );
 
 		it( 'sets #_isRendered true', () => {
@@ -645,7 +645,7 @@ describe( 'Template', () => {
 
 				strongView.set( 'id' );
 
-				expect( () => {
+				expectToThrowCKEditorError( () => {
 					getView( {
 						tag: 'div',
 						children: [
@@ -727,12 +727,12 @@ describe( 'Template', () => {
 		} );
 
 		it( 'throws when wrong template definition', () => {
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				new Template( {
 					tag: 'p',
 					text: 'foo'
 				} ).apply( el );
-			} ).to.throw( CKEditorError, /ui-template-wrong-syntax/ );
+			}, /ui-template-wrong-syntax/ );
 		} );
 
 		it( 'accepts empty template definition', () => {
@@ -1119,15 +1119,15 @@ describe( 'Template', () => {
 				tag: 'div'
 			} );
 
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				tpl.revert( el );
-			} ).to.throw( CKEditorError, /ui-template-revert-not-applied/ );
+			}, /ui-template-revert-not-applied/ );
 
 			tpl.render();
 
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				tpl.revert( el );
-			} ).to.throw( CKEditorError, /ui-template-revert-not-applied/ );
+			}, /ui-template-revert-not-applied/ );
 		} );
 
 		describe( 'text', () => {
@@ -2691,7 +2691,7 @@ describe( 'Template', () => {
 
 		describe( 'children', () => {
 			it( 'should throw when the number of children does not correspond', () => {
-				expect( () => {
+				expectToThrowCKEditorError( () => {
 					extensionTest(
 						{
 							tag: 'p',
@@ -2707,11 +2707,11 @@ describe( 'Template', () => {
 						},
 						'it should fail'
 					);
-				} ).to.throw( CKEditorError, /ui-template-extend-children-mismatch/ );
+				}, /ui-template-extend-children-mismatch/ );
 			} );
 
 			it( 'should throw when no children in target but extending one', () => {
-				expect( () => {
+				expectToThrowCKEditorError( () => {
 					extensionTest(
 						{
 							tag: 'p',
@@ -2725,11 +2725,11 @@ describe( 'Template', () => {
 						},
 						'it should fail'
 					);
-				} ).to.throw( CKEditorError, /ui-template-extend-children-mismatch/ );
+				}, /ui-template-extend-children-mismatch/ );
 			} );
 
 			it( 'should throw when the number of children does not correspond on some deeper level', () => {
-				expect( () => {
+				expectToThrowCKEditorError( () => {
 					extensionTest(
 						{
 							tag: 'p',
@@ -2768,7 +2768,7 @@ describe( 'Template', () => {
 						},
 						'it should fail'
 					);
-				} ).to.throw( CKEditorError, /ui-template-extend-children-mismatch/ );
+				}, /ui-template-extend-children-mismatch/ );
 			} );
 
 			it( 'extends existing - simple', () => {

+ 4 - 3
packages/ckeditor5-ui/tests/view.js

@@ -8,10 +8,11 @@
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import View from '../src/view';
 import Template from '../src/template';
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+
 import Collection from '@ckeditor/ckeditor5-utils/src/collection';
 import ViewCollection from '../src/viewcollection';
 import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
+import { assertCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 let TestView, view, childA, childB;
 
@@ -215,8 +216,8 @@ describe( 'View', () => {
 				view.render();
 				throw new Error( 'This should not be executed.' );
 			} catch ( err ) {
-				expect( err ).to.be.instanceof( CKEditorError );
-				expect( err.message ).to.match( /^ui-view-render-already-rendered:/ );
+				// TODO
+				assertCKEditorError( err, /^ui-view-render-already-rendered:/, view );
 			}
 		} );
 

+ 10 - 9
packages/ckeditor5-ui/tests/viewcollection.js

@@ -5,11 +5,12 @@
 
 /* global document */
 
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import View from '../src/view';
 import ViewCollection from '../src/viewcollection';
 import normalizeHtml from '@ckeditor/ckeditor5-utils/tests/_utils/normalizehtml';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 let collection;
 
@@ -38,12 +39,12 @@ describe( 'ViewCollection', () => {
 
 				const viewA = new View();
 
-				expect( () => {
+				expectToThrowCKEditorError( () => {
 					collection.add( viewA );
 					collection.remove( viewA );
 				} ).to.not.throw();
 
-				expect( () => {
+				expectToThrowCKEditorError( () => {
 					collection.add( viewA );
 					collection.remove( viewA );
 				} ).to.not.throw();
@@ -169,17 +170,17 @@ describe( 'ViewCollection', () => {
 
 	describe( 'delegate()', () => {
 		it( 'should throw when event names are not strings', () => {
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				collection.delegate();
-			} ).to.throw( CKEditorError, /ui-viewcollection-delegate-wrong-events/ );
+			}, /ui-viewcollection-delegate-wrong-events/ );
 
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				collection.delegate( new Date() );
-			} ).to.throw( CKEditorError, /ui-viewcollection-delegate-wrong-events/ );
+			}, /ui-viewcollection-delegate-wrong-events/ );
 
-			expect( () => {
+			expectToThrowCKEditorError( () => {
 				collection.delegate( 'color', new Date() );
-			} ).to.throw( CKEditorError, /ui-viewcollection-delegate-wrong-events/ );
+			}, /ui-viewcollection-delegate-wrong-events/ );
 		} );
 
 		it( 'returns object', () => {