-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckbox.test.tsx
30 lines (26 loc) · 976 Bytes
/
checkbox.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
27
28
29
30
import { render, screen } from "@testing-library/react";
import { createRef } from "react";
import { describe, expect, it } from "vitest";
import { Checkbox } from "./checkbox";
describe("Checkbox", () => {
it("renders without crashing", () => {
render(<Checkbox />);
const checkboxElement = screen.getByRole("checkbox");
expect(checkboxElement).toBeInTheDocument();
});
it("forwards ref correctly", () => {
const ref = createRef<HTMLButtonElement>();
render(<Checkbox ref={ref} />);
expect(ref.current).not.toBeNull();
});
it("applies correct class names", () => {
render(<Checkbox className="test-class" />);
const checkboxElement = screen.getByRole("checkbox");
expect(checkboxElement).toHaveClass("test-class");
});
it("renders CheckIcon when checked", () => {
render(<Checkbox checked />);
const checkIconElement = screen.getByTestId("check-icon");
expect(checkIconElement).toBeInTheDocument();
});
});