Created
December 13, 2019 05:32
-
-
Save sergey-kras/5ab6d56d4341ea92c48f311c751c6e84 to your computer and use it in GitHub Desktop.
Обертка, которая не работает
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
import React, { Component } from 'react'; | |
interface Props { | |
children: JSX.Element | any; | |
prefix?: string; | |
postfix?: string; | |
customParentName?: string; | |
customChildName?: string; | |
} | |
export class SetTestWrapper extends Component<Props> { | |
render() { | |
const parentName = | |
this.props.customParentName | |
|| this.props.children._owner.elementType.name; | |
const childrenName = this.props.customChildName | |
|| this.props.children.type.name | |
|| this.props.children.props.className; | |
const prefix = this.props.prefix ? this.props.prefix + '_' : ''; | |
const postfix = this.props.postfix ? '_' + this.props.postfix : ''; | |
const dataTest = `${prefix}${parentName}_${childrenName}${postfix}`; | |
return ( | |
<div data-test={dataTest}> | |
{this.props.children} | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment