UNPKG

@crossed/primitive

Version:

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

42 lines (41 loc) 1.51 kB
import { Fragment, jsx } from "react/jsx-runtime"; import "@testing-library/jest-dom"; import { render, screen } from "@crossed/test"; import { createLabelMain } from "../Label"; import React, { forwardRef } from "react"; import { Provider } from "../context"; jest.mock("../context"); const Comp = forwardRef((p, ref) => /* @__PURE__ */ jsx("div", { ...p, ref })); const NewComp = createLabelMain(Comp); const ProviderMocked = Provider; describe("createLabelMain", () => { const oldUseId = React.useId; const oldUseRef = React.useRef; beforeEach(() => { React.useId = jest.fn(() => "id"); React.useRef = jest.fn(() => ({ current: void 0 })); ProviderMocked.mockImplementation(({ children }) => /* @__PURE__ */ jsx(Fragment, { children })); }); afterEach(() => { React.useId = oldUseId; React.useRef = oldUseRef; ProviderMocked.mockReset(); }); afterAll(() => { jest.restoreAllMocks(); }); test("init", async () => { const child = "Pass child"; render(/* @__PURE__ */ jsx(NewComp, { children: child })); expect(React.useId).toBeCalled(); expect(React.useRef).toBeCalled(); expect(ProviderMocked).toBeCalled(); expect(ProviderMocked.mock.calls[0][0]).toHaveProperty("id", "id"); expect(ProviderMocked.mock.calls[0][0]).toHaveProperty("inputRef", { current: void 0 }); expect(ProviderMocked.mock.calls[0][0]).toHaveProperty("children"); await screen.findByText(child); }); }); //# sourceMappingURL=Label.spec.js.map