import React from "react"; import { render } from "@testing-library/react"; import { componentDisplayName } from "../utils/componentDisplayName"; import { withWrapper } from "./withWrapper"; interface ExampleProps { a: number; b: number; } function Example(props: ExampleProps): JSX.Element { return
{JSON.stringify(props)};
}
function Wrapper(props: { children: JSX.Element }): JSX.Element {
const { children, ...rest } = props;
return {children};
}
it("withWrapper name", () => {
const Component = withWrapper(Wrapper)(Example);
expect(componentDisplayName.get(Component)).toBe(
"withWrapper.Wrapper(Example)",
);
});
it("withWrapper with default params", () => {
const Component = withWrapper(Wrapper)(Example);
render({"a":0,"b":1}',
);
});
it("withWrapper with empty pickProps", () => {
const Component = withWrapper(Wrapper, { pickProps: [] })(Example);
render({"a":0,"b":1}',
);
});
it("withWrapper with empty omitProps", () => {
const Component = withWrapper(Wrapper, { omitProps: [] })(Example);
render({"a":0,"b":1}',
);
});
it("withWrapper with pickProps", () => {
const Component = withWrapper(Wrapper, { pickProps: ["a"] })(Example);
render({"a":0,"b":1}',
);
});
it("withWrapper with omitProps", () => {
const Component = withWrapper(Wrapper, { omitProps: ["a"] })(Example);
render({"a":0,"b":1}',
);
});