diff --git a/lib/component.js b/lib/component.js index 6ee26c1d..4ce3b901 100644 --- a/lib/component.js +++ b/lib/component.js @@ -572,7 +572,7 @@ class Component extends WebComponent { const attrType = attrSchema.type; if (!ATTR_TYPE_DEFAULTS.hasOwnProperty(attrType)) { throw new Error( - `Invalid type: ${attrType} for attr: ${attr} in attrsSchema. ` + + `Invalid type: ${attrType} for attr: ${attr} in ${this.constructor.name} attrsSchema. ` + `Only (${Object.keys(ATTR_TYPE_DEFAULTS) .map((v) => `'${v}'`) .join(` | `)}) is valid.`, @@ -628,8 +628,9 @@ class Component extends WebComponent { const enumSet = attrSchema.enumSet; if (enumSet && !enumSet.has(attrValue)) { + this._logError(`attrsSchema value error in`, this); throw new Error( - `Invalid value: '${attrValue}' for attr: ${attr}. ` + + `Invalid value: '${attrValue}' for attr: ${attr} in element ${this.tagName}. ` + `Only (${Array.from(enumSet) .map((v) => `'${v}'`) .join(` | `)}) is valid.`, diff --git a/test/server/component.js b/test/server/component.js index d79ae09d..171943a3 100644 --- a/test/server/component.js +++ b/test/server/component.js @@ -186,16 +186,17 @@ describe(`Server-side component renderer`, function () { }); it(`throws error for invalid value in an enum attr`, function () { - const el = new AttrsReflectionApp(); + const el = document.createElement(`attrs-reflection-app`); + el.connectedCallback(); expect(() => el.setAttribute(`str-attr`, `boo!`)).to.throw( - `Invalid value: 'boo!' for attr: str-attr. Only ('hello' | 'world' | '💩🤒🤢☠️ -> 👻🎉💐🎊😱😍') is valid.`, + `Invalid value: 'boo!' for attr: str-attr in element attrs-reflection-app. Only ('hello' | 'world' | '💩🤒🤢☠️ -> 👻🎉💐🎊😱😍') is valid.`, ); }); it(`throws error if there is a malformed attrsSchema type`, function () { expect(() => new BadAttrsSchemaApp()).to.throw( - `Invalid type: bool for attr: bad-attr in attrsSchema. Only ('string' | 'boolean' | 'number' | 'json') is valid.`, + `Invalid type: bool for attr: bad-attr in BadAttrsSchemaApp attrsSchema. Only ('string' | 'boolean' | 'number' | 'json') is valid.`, ); }); });