"use strict";
require('./../_node_modules/@testing-library/jest-dom/dist/extend-expect.cjs');
const react_esm = require('./../_node_modules/@testing-library/react/dist/@testing-library/react.esm.cjs');
const React = require("react");
const useSSRLayoutEffect = require("./useSSRLayoutEffect.cjs");
const dom_esm = require('./../_node_modules/@testing-library/react/_node_modules/@testing-library/dom/dist/@testing-library/dom.esm.cjs');
describe("useSSRLayoutEffect", () => {
  it("should update the DOM when the state changes", () => {
    let setShowRef;
    const Component = () => {
      const [show, setShow] = React.useState(false);
      const [width, setWidth] = React.useState(0);
      setShowRef = setShow;
      useSSRLayoutEffect.useSSRLayoutEffect(() => {
        setWidth(show ? 100 : 50);
      }, [show]);
      return React.createElement("div", { style: { width } }, "Content");
    };
    const { container } = react_esm.render(React.createElement(Component));
    const inner = dom_esm.getQueriesForElement(container).getByText("Content");
    expect(inner).toHaveStyle("width: 50px");
    react_esm.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.useSSRLayoutEffect(() => {
        return cleanup;
      }, []);
      return null;
    };
    const { unmount } = react_esm.render(React.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.useState(false);
      const [width, setWidth] = React.useState(10);
      setShowRef = setShow;
      useSSRLayoutEffect.useDidUpdateSSRLayoutEffect(() => {
        setWidth(show ? 100 : 50);
      }, [show]);
      return React.createElement("div", { style: { width } }, "Content");
    };
    const { container } = react_esm.render(React.createElement(Component));
    const inner = dom_esm.getQueriesForElement(container).getByText("Content");
    expect(inner).toHaveStyle("width: 10px");
    react_esm.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.useSSRLayoutEffect(() => {
        return cleanup;
      }, []);
      return null;
    };
    const { unmount } = react_esm.render(React.createElement(Component));
    expect(cleanup).not.toHaveBeenCalled();
    unmount();
    expect(cleanup).toHaveBeenCalled();
  });
});
//# sourceMappingURL=useSSRLayoutEffect.spec.cjs.map
