test(tile): add unit tests

This commit is contained in:
Eric Liu 2025-03-09 15:31:38 -07:00
commit fc04ad31f3
3 changed files with 61 additions and 7 deletions

41
tests/Tile/Tile.test.ts Normal file
View file

@ -0,0 +1,41 @@
import { render, screen } from "@testing-library/svelte";
import { user } from "../setup-tests";
import Tile from "./Tile.test.svelte";
describe("Tile", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("should render with default class", () => {
render(Tile);
const tile = screen.getByText("Default tile");
expect(tile).toHaveClass("bx--tile");
});
it("should render light variant", () => {
render(Tile);
const lightTile = screen.getByText("Light variant");
expect(lightTile).toHaveClass("bx--tile", "bx--tile--light");
});
it("should handle click events", async () => {
const consoleLog = vi.spyOn(console, "log");
render(Tile);
const tile = screen.getByTestId("click-test");
await user.click(tile);
expect(consoleLog).toHaveBeenCalledWith("clicked");
expect(consoleLog).toHaveBeenCalledTimes(1);
});
it("should pass through additional attributes", () => {
render(Tile);
const tile = screen.getByTestId("attr-test");
expect(tile).toHaveAttribute("title", "Custom title");
expect(tile).toHaveClass("custom-class");
});
});