component-test-setup
Version:
Standardized test setup methods for React components in tests.
20 lines (19 loc) • 811 B
TypeScript
import { FullProps, RenderRtl, SetupComponentType } from "./types";
/**
* Creates a `renderView` function that can be used in unit tests to mount a component.
*
* @param Component - React component to be rendered.
* @param baseProps - Any default props to pass to the component in all tests.
* @example
* ```tsx
* const renderView = setupRtl(ButtonWithText, { onClick: jest.fn() })
*
* const text = 'Hooray!';
* const { props: { onClick }, view } = renderView({ text });
*
* FireEvent.click(view.getByRole('button'));
*
* expect(onClick).toHaveBeenCalledWith(text);
* ```
*/
export declare function setupRtl<ComponentType extends SetupComponentType, BaseProps extends Partial<FullProps<ComponentType>> = {}>(Component: ComponentType, baseProps?: BaseProps): RenderRtl<ComponentType, BaseProps>;