Created
January 9, 2024 12:53
-
-
Save tjunghans/1e650daf072e03603bec7edb7809a408 to your computer and use it in GitHub Desktop.
React Component Mock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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