-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch.test.tsx
26 lines (23 loc) · 1.09 KB
/
switch.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { render, screen } from "@testing-library/react";
import { createRef } from "react";
import { describe, expect, it } from "vitest";
import { Switch } from "./switch";
describe("Switch", () => {
it("renders without crashing", () => {
render(<Switch />);
const switchElement = screen.getByRole("switch");
expect(switchElement).toBeInTheDocument();
});
it("forwards ref correctly", () => {
const ref = createRef<HTMLButtonElement>();
render(<Switch ref={ref} />);
expect(ref.current).not.toBeNull();
});
it("applies correct class names based on state", () => {
render(<Switch />);
const switchElement = screen.getByRole("switch");
expect(switchElement).toHaveClass(
"peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors disabled:cursor-not-allowed data-[state=checked]:bg-primary data-[state=unchecked]:bg-input disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
);
});
});