diff --git a/src/support/testing/testComponent.tsx b/src/support/testing/testComponent.tsx index e0a437b3..0eebfc1b 100644 --- a/src/support/testing/testComponent.tsx +++ b/src/support/testing/testComponent.tsx @@ -59,7 +59,7 @@ export type Decorator< * @param settings settings to apply on the decoration * @returns an updated JSX structure */ - decorator: (Component: React.FC, settings: TSettings) => JSX.Element; + Decorator: React.FC<{ Component: React.FC; settings: TSettings }>; }; const hasAlreadyRendered = ( @@ -71,7 +71,10 @@ const hasAlreadyRendered = ( document.body.firstChild === lastRender.baseElement.firstChild; /** - * Set the component subject of this test + * Set the component subject of this test. + * + * This component should be a FunctionalComponent. If you want + * to test a ClassComponent, you can wrap your component with `makeFC` * * @example ``` * const { renderComponent } = setComponent(YourComponent) @@ -128,8 +131,12 @@ export const setComponent = < } const jsxStructure = (settings.decorators ?? []).reduce( - (result, dec) => - dec.decorator(() => result, decoratorSettings[dec.name]), + (result, dec) => ( + result} + settings={decoratorSettings[dec.name]} + /> + ), , ); @@ -173,6 +180,11 @@ export const setComponent = < }; }; +/** + * Convert a ClassComponent into a FunctionalComponent. + * The ref that can be supplied will be a ref to the instance of the + * ClassComponent. + */ export const makeFC = ( Component: React.ComponentClass, ): React.ForwardRefExoticComponent< diff --git a/src/support/testing/testDecorators.tsx b/src/support/testing/testDecorators.tsx index c826ac73..1bd115f4 100644 --- a/src/support/testing/testDecorators.tsx +++ b/src/support/testing/testDecorators.tsx @@ -7,7 +7,7 @@ import { Context as ResponsiveContext } from "react-responsive"; export const responsiveDecorator: Decorator<"responsive", { width: number }> = { name: "responsive", settings: { width: 1200 }, - decorator: (Component, settings) => ( + Decorator: ({ Component, settings }) => ( @@ -23,7 +23,7 @@ export const dataDecorator = ( > => ({ name: "application", settings: { useTypeName: true, mocks, cache }, - decorator: (Component, settings) => ( + Decorator: ({ Component, settings }) => ( ( + Decorator: ({ Component, settings }) => ( {Object.entries(settings.paths).map(([path, content]) => ( @@ -57,7 +57,7 @@ export const routingDecorator = (): Decorator< export const tableDecorator: Decorator<"table", Record> = { name: "table", settings: {}, - decorator: (Component) => ( + Decorator: ({ Component }) => (