UNPKG

@crossed/primitive

Version:

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

41 lines (40 loc) 1.37 kB
import { jsx } from "react/jsx-runtime"; import "@testing-library/jest-dom"; import { render, screen } from "@crossed/test"; import { createLabelText } from "../LabelText"; import { forwardRef } from "react"; import { useContext } from "../context"; import { Text } from "react-native"; jest.mock("../context"); jest.mock("@crossed/core/src/composeEventHandlers"); const Comp = forwardRef((p, ref) => /* @__PURE__ */ jsx(Text, { ...p, role: "label", ref })); const NewComp = createLabelText(Comp); const useContextMocked = useContext; describe("createLabelMain", () => { beforeEach(() => { useContextMocked.mockImplementation(() => ({ id: "id", inputRef: { current: void 0 } })); }); afterEach(() => { useContextMocked.mockReset(); }); test("init", async () => { const child = "Pass child"; const onPress = jest.fn(); const onFocus = jest.fn(); useContextMocked.mockImplementation(() => ({ id: "id", inputRef: { current: { focus: onFocus } } })); render(/* @__PURE__ */ jsx(NewComp, { onPress, children: child })); expect(useContextMocked).toBeCalled(); const el = await screen.getByText(child); expect(el).toHaveAttribute("id", "label-id"); el.click(); expect(onPress).toHaveBeenCalled(); expect(onFocus).toHaveBeenCalled(); }); }); //# sourceMappingURL=LabelText.spec.js.map