mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
test(tile): add unit tests
This commit is contained in:
parent
39cb29afba
commit
fc04ad31f3
3 changed files with 61 additions and 7 deletions
20
tests/Tile/Tile.test.svelte
Normal file
20
tests/Tile/Tile.test.svelte
Normal file
|
@ -0,0 +1,20 @@
|
|||
<script lang="ts">
|
||||
import { Tile } from "carbon-components-svelte";
|
||||
</script>
|
||||
|
||||
<Tile>Default tile</Tile>
|
||||
|
||||
<Tile light>Light variant</Tile>
|
||||
|
||||
<Tile
|
||||
data-testid="click-test"
|
||||
on:click={() => {
|
||||
console.log("clicked");
|
||||
}}
|
||||
>
|
||||
Clickable tile
|
||||
</Tile>
|
||||
|
||||
<Tile data-testid="attr-test" title="Custom title" class="custom-class">
|
||||
Custom attributes
|
||||
</Tile>
|
41
tests/Tile/Tile.test.ts
Normal file
41
tests/Tile/Tile.test.ts
Normal 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");
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue