Skip to content

Commit

Permalink
chore: add inline script tag test
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaAmaju committed Apr 4, 2024
1 parent 4c171d4 commit 9be893c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/test/apps/basic/src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ app.get("/without-locals", (ctx) => {
});

app.get("/client-assets", (ctx) => ctx.render("client-assets/page"));
app.get("/script/inline", (ctx) => ctx.render("script-inline"));

app.get("/css/inline", (ctx) => ctx.render("css/inline"));
app.get("/css/nested", (ctx) => ctx.render("css/nested/index"));
Expand Down
30 changes: 30 additions & 0 deletions packages/core/test/apps/basic/src/views/script-inline.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Client assets</title>
<script type="module" src="./script.ts"></script>
</head>
<body>
<button data-testid="dec">-</button>
<p data-testid="text"></p>
<button data-testid="inc">+</button>

<script>
const inc = document.querySelector('[data-testid="inc"]');
const dec = document.querySelector('[data-testid="dec"]');
const text = document.querySelector('[data-testid="text"]');
let count = 0;
inc?.addEventListener("click", () => {
if (text) text.textContent = (++count).toString();
});
dec?.addEventListener("click", () => {
if (text) text.textContent = (--count).toString();
});
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions packages/core/test/apps/basic/test/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ test.describe("Views", () => {
await dec.click();
expect(await text.textContent()).toBe("0");
});

test("supports inline script tags", async ({ page }) => {
await page.goto("/script/inline");
const inc = page.getByTestId("inc");
const dec = page.getByTestId("dec");
const text = page.getByTestId("text");
await inc.click();
expect(await text.textContent()).toBe("1");
await dec.click();
expect(await text.textContent()).toBe("0");
});
});

test.describe("CSS", () => {
Expand Down

0 comments on commit 9be893c

Please sign in to comment.