Skip to content

Instantly share code, notes, and snippets.

@tjunghans
Created January 9, 2024 12:53
Show Gist options
  • Save tjunghans/1e650daf072e03603bec7edb7809a408 to your computer and use it in GitHub Desktop.
Save tjunghans/1e650daf072e03603bec7edb7809a408 to your computer and use it in GitHub Desktop.
React Component Mock
import React, { type DetailedHTMLProps, type HTMLAttributes } from "react";
export const createComponentMock = <
T extends DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
>(
componentName: string
) => {
const fakeComponent = (props: T) => (
<div data-testid={componentName} {...props} />
);
fakeComponent.displayName = componentName;
return fakeComponent;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment