diff --git a/hsp/rt/cptcomponent.js b/hsp/rt/cptcomponent.js index 992babf..444a77f 100644 --- a/hsp/rt/cptcomponent.js +++ b/hsp/rt/cptcomponent.js @@ -87,7 +87,9 @@ exports.$CptComponent = { for (var i = 0, sz = this.atts.length; sz > i; i++) { att = atts[i]; nm = att.name; - if (this.ctlAttributes[nm].type!=="template") { + if (!this.ctlAttributes || !this.ctlAttributes[nm]) { + throw new Error('The attribute "' + nm + '" was used but the component doesn\'t define this attribute.'); + } else if (this.ctlAttributes[nm].type!=="template") { attributes[nm]=att.getValue(eh, pvs, null); } } diff --git a/test/rt/cpterrors.spec.hsp b/test/rt/cpterrors.spec.hsp new file mode 100644 index 0000000..c87a58a --- /dev/null +++ b/test/rt/cpterrors.spec.hsp @@ -0,0 +1,51 @@ +var klass=require("hsp/klass"), + ht=require("hsp/utils/hashtester"); + +var FooNoAttrsCtrl=klass({ +}); + +var FooEmptyAttrsCtrl=klass({ + attributes: { + } +}); + +{template fooNoAttrs using ctrl:FooNoAttrsCtrl} +
foo
+{/template} + +{template fooEmptyAttrs using ctrl:FooEmptyAttrsCtrl} +
foo
+{/template} + +{template test1} +<#fooNoAttrs foo="bar"> +{/template} + +{template test2} +<#fooEmptyAttrs foo="bar"> +{/template} + +describe('error reporting for custom components', function() { + + var h; + beforeEach(function() { + h=ht.newTestContext(); + }); + + it('attribute used for a component without attributes', function() { + expect(function() { + test1().render(h.container); + }).to.throwException(/The attribute "foo" was used but the component doesn't define this attribute./); + }); + + it('attribute used for a component without attributes', function() { + expect(function() { + test2().render(h.container); + } ).to.throwException(/The attribute "foo" was used but the component doesn't define this attribute./); + }); + + afterEach(function(){ + h.$dispose(); + }); + +}); \ No newline at end of file