UNPKG

@crossed/primitive

Version:

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

68 lines (67 loc) 2.32 kB
"use strict"; var import_useEvent = require("../useEvent"); var import_react = require("react"); jest.mock("react"); const useCallbackMocked = import_react.useCallback; const useEffectMocked = import_react.useEffect; const useLayoutEffectMocked = import_react.useLayoutEffect; const useRefMocked = import_react.useRef; describe("useEvent", () => { beforeEach(() => { useCallbackMocked.mockImplementation((e) => e); useEffectMocked.mockImplementation((e) => e()); useLayoutEffectMocked.mockImplementation((e) => e()); useRefMocked.mockImplementation(() => ({ current: void 0 })); }); afterEach(() => { useCallbackMocked.mockReset(); useEffectMocked.mockReset(); useLayoutEffectMocked.mockReset(); useRefMocked.mockReset(); }); test("with callback", () => { const callback = jest.fn(); const event = (0, import_useEvent.useEvent)(callback); expect(useRefMocked).toBeCalled(); expect(useLayoutEffectMocked).toBeCalled(); expect(useCallbackMocked).toBeCalled(); expect(typeof event).toBe("function"); event(); expect(callback).toBeCalled(); }); test("without callback", () => { const event = (0, import_useEvent.useEvent)(); expect(useRefMocked).toBeCalled(); expect(useLayoutEffectMocked).toBeCalled(); expect(useCallbackMocked).toBeCalled(); expect(typeof event).toBe("function"); event(); }); }); describe("useGet", () => { beforeEach(() => { useCallbackMocked.mockImplementation((e) => e); useEffectMocked.mockImplementation((e) => e()); useLayoutEffectMocked.mockImplementation((e) => e()); useRefMocked.mockImplementation(() => ({ current: void 0 })); }); afterEach(() => { useCallbackMocked.mockReset(); useEffectMocked.mockReset(); useLayoutEffectMocked.mockReset(); useRefMocked.mockReset(); }); test("simple", () => { const callback = jest.fn(); const event = (0, import_useEvent.useGet)(callback); expect(useRefMocked).toBeCalled(); expect(useLayoutEffectMocked).toBeCalled(); expect(useCallbackMocked).toBeCalled(); expect(typeof event).toBe("function"); const eventReturn = event(); expect(typeof eventReturn).toBe("function"); eventReturn(); expect(callback).toBeCalled(); }); }); //# sourceMappingURL=useEvent.spec.js.map