import { render } from "@testing-library/react"; import React from "react"; import { componentDisplayName } from "../utils/componentDisplayName"; import { withDefault } from "./withDefault"; function Example(props: { someProp: number }): JSX.Element { return
{JSON.stringify(props)};
}
it("withDefault name", () => {
const Component = withDefault("someProp", 1)(Example);
expect(componentDisplayName.get(Component)).toBe(
"withDefault.someProp(Example)",
);
});
it("withDefault with value", () => {
const Component = withDefault("someProp", 1)(Example);
render({"someProp":1}');
});
it("withDefault with another value", () => {
const Component = withDefault("anotherProp", 1)(Example);
render({"anotherProp":1,"someProp":2}',
);
});
it("withDefault a new property as value", () => {
const Component = withDefault("anotherProp", 10)(Example);
render({"anotherProp":10,"someProp":5}',
);
});
it("withDefault overridden", () => {
const Component = withDefault("someProp", 10)(Example);
render({"someProp":20}',
);
});