import React from 'react'; export interface ComponentMockProps { onClick: () => void; onChange: () => void; 'data-testid': string; className?: string; } export function createMockComponent( componentName: string, defaultDataTestId: string = '', ): React.FC { const NamedComponentMock = ({ children, 'data-testid': dataTestId = defaultDataTestId || componentName, onClick, onChange, className, ...props }: React.PropsWithChildren) => (
{children}
); const component = jest.fn().mockImplementation(NamedComponentMock); // @ts-ignore HACK so that snapshots do not suffer from `mockConstructor` instead of the component name component.displayName = componentName; return component; }