UNPKG

@crossed/ui

Version:

A universal & performant styling library for React Native, Next.js & React

40 lines (39 loc) 1.63 kB
import { jsx } from "react/jsx-runtime"; import { act } from "react"; import { IconButton } from "../IconButton"; import { X } from "@crossed/unicons"; import { userEvent, render, screen } from "@crossed/test"; describe("IconButton", () => { it("renders correctly", () => { render(/* @__PURE__ */ jsx(IconButton, {})); const button = screen.getByRole("button"); expect(button).toBeTruthy(); }); it("renders the provided children", () => { render( /* @__PURE__ */ jsx(IconButton, { children: /* @__PURE__ */ jsx(X, {}) }) ); expect(screen.getByRole("button")).toMatchSnapshot(); }); it("calls onPress when pressed", async () => { const onPressMock = jest.fn(); render(/* @__PURE__ */ jsx(IconButton, { onPress: onPressMock })); const button = screen.getByRole("button"); await act(() => userEvent.click(button)); expect(onPressMock).toHaveBeenCalledTimes(1); }); it("does not call onPress when disabled", async () => { const onPressMock = jest.fn(); render(/* @__PURE__ */ jsx(IconButton, { onPress: onPressMock, disabled: true })); const button = screen.getByRole("button"); await act(() => userEvent.click(button, { pointerEventsCheck: 0 })); expect(onPressMock).not.toHaveBeenCalled(); }); it("renders function-based children correctly", () => { const childMock = jest.fn(() => /* @__PURE__ */ jsx(X, {})); render(/* @__PURE__ */ jsx(IconButton, { children: childMock })); expect(childMock).toHaveBeenCalled(); expect(screen.getByRole("button")).toMatchSnapshot(); }); }); //# sourceMappingURL=IconButton.spec.js.map