Forked from https://github.com/welldone-software/babel-plugin-react-add-test-id
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-id="Foo-Wrapper">
<Bar data-test-id="Foo-Wrapper-Bar">
</Wrapper>
yarn add @irruputuncu/babel-plugin-react-add-test-id
or
npm install @irruputuncu/babel-plugin-react-add-test-id
in .babelrc
"plugins": [
"@irruputuncu/babel-plugin-react-add-test-id",
...
Property | Type | Default | Description |
---|---|---|---|
attrName | String | data-test-id |
Define the attribute name |
mode | String | regular |
One of minimal , regular , full |
ignoreElements | Array of Strings | [div , input , a , button , span , p , br , hr , ul , ol , li , img , form , h1 , h2 , h3 , h4 , h5 , h6 , svg , path , g ] |
Avoid adding test id on those elements |
additionalIgnoreElements | Array of Strings | [] | Add extra ignoreElements |
delimiter | String | - |
Separate components name with the delimiter |
in .babelrc
"plugins": [
["@irruputuncu/babel-plugin-react-add-test-id", {"attrName": "data-test-id-example"}],