test: add test for svelte components

This commit is contained in:
2026-02-08 04:14:03 +05:00
parent db26272ac5
commit 1a0d99828e
16 changed files with 661 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
import { render, screen } from "@testing-library/svelte";
import { describe, expect, it } from "vitest";
import Badge from "$components/ui/Badge.svelte";
describe("Badge.svelte", () => {
it("should render with string text", () => {
render(Badge, {
props: {
text: "Test Badge",
},
});
expect(screen.getByText("Test Badge")).toBeInTheDocument();
});
it("should render with number text", () => {
render(Badge, {
props: {
text: 42,
},
});
expect(screen.getByText("42")).toBeInTheDocument();
});
it("should render with empty string", () => {
const { container } = render(Badge, {
props: {
text: "",
},
});
const badge = container.querySelector(".badge");
expect(badge).toBeInTheDocument();
expect(badge).toHaveTextContent("");
});
it("should render with zero", () => {
render(Badge, {
props: {
text: 0,
},
});
expect(screen.getByText("0")).toBeInTheDocument();
});
});