Created
September 19, 2021 09:44
-
-
Save majirosstefan/ffee87c8c97b49e92c115f22ebaec06b to your computer and use it in GitHub Desktop.
Cavy e2e React Native Test Utility
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 {useCavy, wrap} from 'cavy'; | |
import React from 'react'; | |
export function testable<P>( | |
FunctionalComponent: React.FunctionComponent<P>, | |
): React.FunctionComponent<P & {testID?: string}> { | |
// if (!__DEV__) { | |
// return FunctionalComponent; | |
// } | |
const ClassComponent = wrap(FunctionalComponent); | |
return (props: P & {testID?: string}) => { | |
const generateTestHook = useCavy(); | |
return ( | |
<ClassComponent | |
{...props} | |
ref={props.testID == null ? undefined : generateTestHook(props.testID)} | |
/> | |
); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment