Last active
September 26, 2019 15:14
-
-
Save mptorz/5a23dca0afe8fb9c1f93cd8cbfb630c4 to your computer and use it in GitHub Desktop.
Useful wrappers to add identifier with Cavy e2e test library
This file contains 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
// EXAMPLE USAGE: | |
// export default withCavyCustomIdentifier('SomeCustomIdentifier')(SomeScreen) | |
export const withCavyCustomIdentifier = (identifier: string) => <T,>(originalComponent: ComponentType<T>) => { | |
const ComponentWithIdentifier = (props: T) => { | |
const WrappedComponent = !!originalComponent.prototype.render ? originalComponent : wrap(originalComponent) | |
const generateTestHook = useCavy() | |
return (<WrappedComponent {...props} ref={generateTestHook(identifier)} />) | |
} | |
return ComponentWithIdentifier | |
} | |
// EXAMPLE USAGE: | |
// export default withCavyIdentifier(SomeScreen) | |
export const withCavyIdentifier = <T,>(originalComponent: ComponentType<T>) => { | |
const ComponentWithIdentifier = (props: T) => { | |
const WrappedComponent = !!originalComponent.prototype.render ? originalComponent : wrap(originalComponent) | |
const generateTestHook = useCavy() | |
return (<WrappedComponent {...props} ref={generateTestHook(originalComponent.name)} />) | |
} | |
return ComponentWithIdentifier | |
} | |
// then we can easily use: | |
// spec.exists('SomeCustomIdentifier') or spec.exists('SomeScreen') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment