Babel plugin that automatically adds data-testid attributes to JSX elements based on the component name. Current version 0.2.0, stable maintenance mode. Supports custom attribute names and multiple attributes via options. Does not support class components. Compared to alternatives like babel-plugin-jsx-remove-data-test-id, this plugin focuses on adding rather than stripping test IDs.
npm install babel-plugin-react-data-testidVerified import paths — ran on the pinned version, not inferred.
Shows installation, Babel config setup, and expected transformation of JSX component names to data-testid attributes.
Refactor class components to functional components or manually add data-testid.
Ensure your component is a function, not a class. Convert class component to function if needed.