@crossed/ui
Version:
A universal & performant styling library for React Native, Next.js & React
48 lines (47 loc) • 1.86 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { render, screen, userEvent } from "@crossed/test";
import { CloseButton } from "../CloseButton";
import { inlineStyle } from "@crossed/styled";
describe("CloseButton", () => {
it("renders correctly with default props", () => {
render(/* @__PURE__ */ jsx(CloseButton, {}));
const button = screen.getByRole("button", { name: /close/i });
expect(button).toBeTruthy();
expect(button).toHaveAttribute("aria-label", "Close");
});
it("calls onPress when clicked", async () => {
const onPressMock = jest.fn();
render(/* @__PURE__ */ jsx(CloseButton, { onPress: onPressMock }));
const button = screen.getByRole("button", { name: /close/i });
await userEvent.click(button);
expect(onPressMock).toHaveBeenCalledTimes(1);
});
it("does not call onPress when disabled", async () => {
const onPressMock = jest.fn();
render(/* @__PURE__ */ jsx(CloseButton, { onPress: onPressMock, disabled: true }));
const button = screen.getByRole("button", { name: /close/i });
await userEvent.click(button, { pointerEventsCheck: 0 });
expect(onPressMock).not.toHaveBeenCalled();
expect(button).toBeDisabled();
});
it("applies custom props and styles", () => {
render(
/* @__PURE__ */ jsx(
CloseButton,
{
testID: "close-button",
style: inlineStyle(() => ({ base: { opacity: 0.8 } }))
}
)
);
const button = screen.getByTestId("close-button");
expect(button).toBeTruthy();
});
it("renders the icon with the correct size", () => {
render(/* @__PURE__ */ jsx(CloseButton, {}));
const icon = screen.getByLabelText("Close").children[0];
expect(icon).toHaveAttribute("width", "16");
expect(icon).toHaveAttribute("height", "16");
});
});
//# sourceMappingURL=CloseButton.spec.js.map