-
Notifications
You must be signed in to change notification settings - Fork 618
fix(fast-html): add errors fixture for f-template error cases #7406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7759534
ad14aa4
c0e9bb5
56635ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||
| export const debugMessages = { | ||||||
| [2000 /* noTemplateProvided */]: `The first child of the <f-template> must be a <template>, this is missing from ${name}.`, | ||||||
| [2001 /* moreThanOneTemplateProvided */]: `There can only be one <template> inside the <f-template>, you must add one for ${name}.`, | ||||||
|
||||||
| [2001 /* moreThanOneTemplateProvided */]: `There can only be one <template> inside the <f-template>, you must add one for ${name}.`, | |
| [2001 /* moreThanOneTemplateProvided */]: `There can only be one <template> inside the <f-template>; remove any extra <template> elements and keep exactly one for ${name}.`, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,5 @@ | |
| */ | ||
| export const enum Message { | ||
| noTemplateProvided = 2000, | ||
| moreThanOneTemplateProvided = 2001, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { expect, test } from "@playwright/test"; | ||
|
|
||
| test.describe("f-template errors", () => { | ||
| test("throws an error when no template element is present", async ({ page }) => { | ||
| await page.addInitScript(() => { | ||
| (window as any).__errors = []; | ||
| window.addEventListener("unhandledrejection", event => { | ||
| (window as any).__errors.push( | ||
| event.reason?.message ?? String(event.reason), | ||
| ); | ||
| }); | ||
|
Comment on lines
+7
to
+11
|
||
| }); | ||
|
Comment on lines
+4
to
+12
|
||
|
|
||
| await page.goto("/fixtures/errors/"); | ||
|
|
||
| await expect | ||
| .poll(async () => { | ||
| const errors: string[] = await page.evaluate( | ||
| () => (window as any).__errors, | ||
| ); | ||
| return errors.some(msg => msg.includes("must be a <template>")); | ||
| }) | ||
| .toBe(true); | ||
| }); | ||
|
|
||
| test("throws an error when multiple template elements are present", async ({ | ||
| page, | ||
| }) => { | ||
| await page.addInitScript(() => { | ||
| (window as any).__errors = []; | ||
| window.addEventListener("unhandledrejection", event => { | ||
| (window as any).__errors.push( | ||
| event.reason?.message ?? String(event.reason), | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| await page.goto("/fixtures/errors/"); | ||
|
|
||
| await expect | ||
| .poll(async () => { | ||
| const errors: string[] = await page.evaluate( | ||
| () => (window as any).__errors, | ||
| ); | ||
| return errors.some(msg => msg.includes("only be one <template>")); | ||
| }) | ||
| .toBe(true); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>Errors</title> | ||
| </head> | ||
| <body> | ||
| <test-element-no-template></test-element-no-template> | ||
| <test-element-multiple-templates></test-element-multiple-templates> | ||
| <f-template name="test-element-no-template"> | ||
| <span>No template element provided</span> | ||
| </f-template> | ||
| <f-template name="test-element-multiple-templates"> | ||
| <template><span>First template</span></template> | ||
| <template><span>Second template</span></template> | ||
| </f-template> | ||
| <script type="module" src="./main.ts"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { FASTElement } from "@microsoft/fast-element"; | ||
| import { TemplateElement } from "@microsoft/fast-html"; | ||
|
|
||
| class TestElementNoTemplate extends FASTElement {} | ||
| FASTElement.define(TestElementNoTemplate, { name: "test-element-no-template" }); | ||
|
|
||
| class TestElementMultipleTemplates extends FASTElement {} | ||
| FASTElement.define(TestElementMultipleTemplates, { | ||
| name: "test-element-multiple-templates", | ||
| }); | ||
|
|
||
| TemplateElement.define({ | ||
| name: "f-template", | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debugMessagesentries are defined using template literals, so${name}is being interpolated by JavaScript at module evaluation time (e.g. towindow.namein browsers) instead of being left as a placeholder forFAST.error(code, { name })to format. These messages should be plain strings containing the literal${name}placeholder soformatMessage()can substitute runtime values.