Skip to content

Commit

Permalink
test: basic tests for Chip (#753)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Dial <[email protected]>
  • Loading branch information
asharonbaltazar and mdial89f committed Sep 9, 2024
1 parent 521fcb3 commit fb5f650
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions react-app/src/components/Chip/Chip.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { render } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, test, vi } from "vitest";
import { Chip } from ".";

describe("Chip", () => {
test("onChipClick is called", async () => {
const mockedOnChipClick = vi.fn();

const { container } = render(<Chip onChipClick={mockedOnChipClick} />);

const chipButton = container.getElementsByClassName(
"h-8 py-2 cursor-pointer",
)[0];

await userEvent.click(chipButton);

expect(mockedOnChipClick).toHaveBeenCalled();
});

test("onIconClick is called", async () => {
const mockedOnIconClick = vi.fn();

const { getByRole } = render(<Chip onIconClick={mockedOnIconClick} />);

const chipButton = getByRole("button");

await userEvent.click(chipButton);

expect(mockedOnIconClick).toHaveBeenCalled();
});

test("noIcon or destructive variants do not render an icon", () => {
const { queryByRole, rerender } = render(<Chip variant="destructive" />);

expect(queryByRole("button")).not.toBeInTheDocument();

rerender(<Chip variant="noIcon" />);

expect(queryByRole("button")).not.toBeInTheDocument();
});
});

0 comments on commit fb5f650

Please sign in to comment.