const Foo = () =>
<Bar>
<div>
</Bar>
const Foo = () =>
<Bar data-test-id="Foo-Bar">
<div data-test-id="Foo-Bar-div">
</Bar>
const Wrapper = styled.div`...`
const Bar = styled.div`...`
const Foo = () =>
<Wrapper>
<Bar>
</Wrapper>
const Wrapper = styled.div`...`
const Bar = styled.div`...`
const Foo = () =>
<Wrapper data-test="Foo-Wrapper">
<Bar data-test="Foo-Wrapper-Bar">
</Wrapper>
yarn add davidgustys/babel-plugin-react-add-data-attribute
or
npm install davidgustys/babel-plugin-react-add-data-attribute
in .babelrc
"plugins": [
"davidgustys/babel-plugin-react-add-data-attribute",
...