Skip to content

Instantly share code, notes, and snippets.

@majirosstefan
Created September 19, 2021 09:44
Show Gist options
  • Save majirosstefan/ffee87c8c97b49e92c115f22ebaec06b to your computer and use it in GitHub Desktop.
Save majirosstefan/ffee87c8c97b49e92c115f22ebaec06b to your computer and use it in GitHub Desktop.
Cavy e2e React Native Test Utility
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