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