import './../_node_modules/@testing-library/jest-dom/dist/extend-expect.js';
import { render, act } from './../_node_modules/@testing-library/react/dist/@testing-library/react.esm.js';
import React__default from "react";
import { useSSRLayoutEffect, useDidUpdateSSRLayoutEffect } from "./useSSRLayoutEffect.js";
import { getQueriesForElement } from './../_node_modules/@testing-library/react/_node_modules/@testing-library/dom/dist/@testing-library/dom.esm.js';
describe("useSSRLayoutEffect", () => {
  it("should update the DOM when the state changes", () => {
    let setShowRef;
    const Component = () => {
      const [show, setShow] = React__default.useState(false);
      const [width, setWidth] = React__default.useState(0);
      setShowRef = setShow;
      useSSRLayoutEffect(() => {
        setWidth(show ? 100 : 50);
      }, [show]);
      return React__default.createElement("div", { style: { width } }, "Content");
    };
    const { container } = render(React__default.createElement(Component));
    const inner = getQueriesForElement(container).getByText("Content");
    expect(inner).toHaveStyle("width: 50px");
    act(() => setShowRef == null ? void 0 : setShowRef(true));
    expect(inner).toHaveStyle("width: 100px");
  });
  it("should call the cleanup function when unmounting", () => {
    const cleanup = jest.fn();
    const Component = () => {
      useSSRLayoutEffect(() => {
        return cleanup;
      }, []);
      return null;
    };
    const { unmount } = render(React__default.createElement(Component));
    expect(cleanup).not.toHaveBeenCalled();
    unmount();
    expect(cleanup).toHaveBeenCalled();
  });
});
describe("useDidUpdateSSRLayoutEffect", () => {
  it("should update the DOM when the state changes, but NOT on the first render", () => {
    let setShowRef;
    const Component = () => {
      const [show, setShow] = React__default.useState(false);
      const [width, setWidth] = React__default.useState(10);
      setShowRef = setShow;
      useDidUpdateSSRLayoutEffect(() => {
        setWidth(show ? 100 : 50);
      }, [show]);
      return React__default.createElement("div", { style: { width } }, "Content");
    };
    const { container } = render(React__default.createElement(Component));
    const inner = getQueriesForElement(container).getByText("Content");
    expect(inner).toHaveStyle("width: 10px");
    act(() => setShowRef == null ? void 0 : setShowRef(true));
    expect(inner).toHaveStyle("width: 100px");
  });
  it("should call the cleanup function when unmounting", () => {
    const cleanup = jest.fn();
    const Component = () => {
      useSSRLayoutEffect(() => {
        return cleanup;
      }, []);
      return null;
    };
    const { unmount } = render(React__default.createElement(Component));
    expect(cleanup).not.toHaveBeenCalled();
    unmount();
    expect(cleanup).toHaveBeenCalled();
  });
});
//# sourceMappingURL=useSSRLayoutEffect.spec.js.map
