https://github.com/welldone-software/babel-plugin-react-add-test-id
https://github.com/welldone-software/babel-plugin-react-add-test-id
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/welldone-software/babel-plugin-react-add-test-id
- Owner: welldone-software
- Created: 2020-03-05T06:16:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-06-17T02:43:11.000Z (about 3 years ago)
- Last Synced: 2025-10-05T07:21:21.766Z (9 months ago)
- Language: JavaScript
- Size: 620 KB
- Stars: 5
- Watchers: 3
- Forks: 10
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# babel-plugin-react-add-test-id
## Example
#### in
```
const Foo = () =>
```
#### out
```
const Foo = () =>
```
## Useful with styled-components
#### in
```
const Wrapper = styled.div`...`
const Bar = styled.div`...`
const Foo = () =>
```
#### out
```
const Wrapper = styled.div`...`
const Bar = styled.div`...`
const Foo = () =>
```
## Install
`yarn add @welldone-software/babel-plugin-react-add-test-id`
or
`npm install @welldone-software/babel-plugin-react-add-test-id`
## Usage
in .babelrc
```
"plugins": [
"@welldone-software/babel-plugin-add-test-id",
...
```
## Options
| 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": [
["@welldone-software/babel-plugin-add-test-id", {"attrName": "data-test-id-example"}],
```