Skip to content

Instantly share code, notes, and snippets.

@sergey-kras
Created December 13, 2019 05:32
Show Gist options
  • Save sergey-kras/5ab6d56d4341ea92c48f311c751c6e84 to your computer and use it in GitHub Desktop.
Save sergey-kras/5ab6d56d4341ea92c48f311c751c6e84 to your computer and use it in GitHub Desktop.
Обертка, которая не работает
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