diff --git a/change/@microsoft-fast-html-a4161f8e-9273-42b3-9c6f-95249dd0ff2e.json b/change/@microsoft-fast-html-a4161f8e-9273-42b3-9c6f-95249dd0ff2e.json new file mode 100644 index 00000000000..7fcb6d7e28b --- /dev/null +++ b/change/@microsoft-fast-html-a4161f8e-9273-42b3-9c6f-95249dd0ff2e.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "fix(fast-html): add errors fixture for f-template error cases", + "packageName": "@microsoft/fast-html", + "email": "7559015+janechu@users.noreply.github.com", + "dependentChangeType": "none" +} diff --git a/packages/fast-html/src/components/template.ts b/packages/fast-html/src/components/template.ts index b7c59e808f2..08baa7d2cd3 100644 --- a/packages/fast-html/src/components/template.ts +++ b/packages/fast-html/src/components/template.ts @@ -239,9 +239,9 @@ class TemplateElement extends FASTElement { ); } - const template = this.getElementsByTagName("template").item(0); + const templates = this.getElementsByTagName("template"); - if (template) { + if (templates.length === 1) { // Callback: Before template has been evaluated and assigned TemplateElement.lifecycleCallbacks.templateWillUpdate?.(name); @@ -281,6 +281,10 @@ class TemplateElement extends FASTElement { values, ); } + } else if (templates.length > 1) { + throw FAST.error(Message.moreThanOneTemplateProvided, { + name: this.name, + }); } else { throw FAST.error(Message.noTemplateProvided, { name: this.name }); } diff --git a/packages/fast-html/src/debug.ts b/packages/fast-html/src/debug.ts index 18348fac9a3..87140bcaae2 100644 --- a/packages/fast-html/src/debug.ts +++ b/packages/fast-html/src/debug.ts @@ -1,3 +1,6 @@ export const debugMessages = { - [2000 /* noTemplateProvided */]: `The first child of the must be a