Skip to content

Commit

Permalink
test(e2e): add test for LineNumbers
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Dec 29, 2024
1 parent 8b3008d commit 88f7234
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
15 changes: 15 additions & 0 deletions tests/e2e/LineNumbers.test.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script lang="ts">
import Highlight, { LineNumbers } from "svelte-highlight";
import typescript from "svelte-highlight/languages/typescript";
import horizonDark from "svelte-highlight/styles/horizon-dark";
const code = "const add = (a: number, b: number) => a + b";
</script>

<svelte:head>
{@html horizonDark}
</svelte:head>

<Highlight language={typescript} {code} let:highlighted>
<LineNumbers {highlighted} />
</Highlight>
16 changes: 15 additions & 1 deletion tests/e2e/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect, test } from "@playwright/experimental-ct-svelte";
import Highlight from "./Highlight.test.svelte";
import HighlightAuto from "./HighlightAuto.test.svelte";
import LineNumbers from "./LineNumbers.test.svelte";
import SvelteHighlight from "./SvelteHighlight.test.svelte";

test.use({ viewport: { width: 1200, height: 600 } });

test("Highlight", async ({ mount, page }) => {
Expand All @@ -18,10 +18,24 @@ test("Highlight", async ({ mount, page }) => {

test("HighlightAuto", async ({ mount, page }) => {
await mount(HighlightAuto);

await expect(page.locator(".hljs-selector-tag")).toHaveText("body");
await expect(page.locator(".hljs-attribute")).toHaveText("background");
await expect(page.locator(".hljs-number")).toHaveText("#000");

// Language tag
await expect(page.locator("pre")).toHaveAttribute("data-language", "css");
});

test("SvelteHighlight", async ({ mount, page }) => {
await mount(SvelteHighlight);
await expect(page.locator(".hljs-attr")).toHaveText("on:click");
});

test("LineNumbers", async ({ mount, page }) => {
await mount(LineNumbers);
await expect(page.getByText("1")).toBeVisible();

await expect(page.locator(".hljs-keyword")).toHaveText("const");
await expect(page.locator(".hljs-title")).toHaveText("add");
});

0 comments on commit 88f7234

Please sign in to comment.