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(); expect(document.body.children[0].innerHTML).toBe('
{"someProp":1}
'); }); it("withDefault with another value", () => { const Component = withDefault("anotherProp", 1)(Example); render(); expect(document.body.children[0].innerHTML).toBe( '
{"anotherProp":1,"someProp":2}
', ); }); it("withDefault a new property as value", () => { const Component = withDefault("anotherProp", 10)(Example); render(); expect(document.body.children[0].innerHTML).toBe( '
{"anotherProp":10,"someProp":5}
', ); }); it("withDefault overridden", () => { const Component = withDefault("someProp", 10)(Example); render(); expect(document.body.children[0].innerHTML).toBe( '
{"someProp":20}
', ); });