ソースを参照

Throw when rendering a templateless View instance.

Aleksander Nowodzinski 10 年 前
コミット
8a9117e7c3

+ 13 - 1
packages/ckeditor5-engine/src/ui/view.js

@@ -12,7 +12,12 @@
  * @extends Model
  */
 
-CKEDITOR.define( [ 'collection', 'model', 'ui/template' ], function( Collection, Model, Template ) {
+CKEDITOR.define( [
+	'collection',
+	'model',
+	'ui/template',
+	'ckeditorerror'
+], function( Collection, Model, Template, CKEditorError ) {
 	class View extends Model {
 		/**
 		 * Creates an instance of the {@link View} class.
@@ -109,6 +114,13 @@ CKEDITOR.define( [ 'collection', 'model', 'ui/template' ], function( Collection,
 		 * @returns {HTMLElement}
 		 */
 		render() {
+			if ( !this.template ) {
+				throw new CKEditorError(
+					'ui-view-notemplate: This View implements no template to render.',
+					{ view: this }
+				);
+			}
+
 			this._template = new Template( this.template );
 
 			return this._template.render();

+ 2 - 2
packages/ckeditor5-engine/tests/ui/view/view.js

@@ -7,7 +7,7 @@
 
 'use strict';
 
-var modules = bender.amd.require( 'ckeditor', 'ui/view' );
+var modules = bender.amd.require( 'ckeditor', 'ui/view', 'ckeditorerror' );
 
 describe( 'View', function() {
 	var view;
@@ -27,7 +27,7 @@ describe( 'View', function() {
 	} );
 
 	it( 'has no default element', function() {
-		expect( view.el ).to.be.null();
+		expect( () => view.el ).to.throw( modules.ckeditorerror );
 	} );
 
 	it( 'has no default template', function() {