test: update tests

This commit is contained in:
2026-02-12 03:44:31 +05:00
parent 9e1eeb57bc
commit 95d7c81cdf
19 changed files with 413 additions and 484 deletions
+24 -3
View File
@@ -1,5 +1,6 @@
import Button from "$components/ui/Button.svelte";
import { fireEvent, render, screen } from "@testing-library/svelte";
import { render, screen } from "@testing-library/svelte";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import MockIcon from "./MockIcon.svelte";
@@ -25,11 +26,15 @@ describe("Button.svelte", () => {
},
});
expect(screen.getByRole("button", { name: /test button/i })).toBeInTheDocument();
const button = screen.getByRole("button", { name: /test button/i });
expect(button).toBeInTheDocument();
expect(button.textContent.trim()).toBe("");
});
it("should call onclick handler", async () => {
const onclick = vi.fn();
const user = userEvent.setup();
render(Button, {
props: {
icon: MockIcon,
@@ -40,11 +45,27 @@ describe("Button.svelte", () => {
});
const button = screen.getByRole("button", { name: /test button/i });
await fireEvent.click(button);
await user.click(button);
expect(onclick).toHaveBeenCalledTimes(1);
});
it("should not throw error when clicked without onclick prop", async () => {
const user = userEvent.setup();
render(Button, {
props: {
icon: MockIcon,
label: "Click me",
ariaLabel: "Test button",
},
});
const button = screen.getByRole("button", { name: /test button/i });
expect(() => user.click(button)).not.toThrow();
});
it("should be disabled when disabled prop is true", () => {
render(Button, {
props: {