eslint-plugin-angular-test-ids is an ESLint plugin designed to enforce the presence of specific attributes, typically `data-test`, on HTML elements within Angular templates. Currently at version `1.0.6`, this plugin offers a practical solution for development teams where end-to-end testing strategies rely on stable identifiers. While the plugin's author expresses a preference for user-visible labels, it acknowledges the widespread industry need for test IDs often mandated by QA processes. Key differentiators include its deep integration with `@angular-eslint/template-parser` for accurate Angular template analysis and highly flexible configuration options. Users can customize the required attribute name (e.g., `data-test`, `test-id`) and precisely define the list of elements that must include this attribute, supporting both native HTML elements and Angular Material components. This allows teams to tailor enforcement rules to their project's specific requirements, making it a robust tool for maintaining testability in Angular applications.
npm install eslint-plugin-angular-test-idsVerified import paths — ran on the pinned version, not inferred.
Configures ESLint in an Angular project to use the `angular-test-ids` plugin, enforcing a custom `data-test-id` attribute on buttons, inputs, and custom `div[role='button']` elements.
Ensure your `.eslintrc` file explicitly defines `"parser": "@angular-eslint/template-parser"` for HTML files, or extends a configuration that does, such as `"extends": ["plugin:@angular-eslint/template/recommended"]`.
Use the `addElements` option to append custom selectors to the default list, or `overrideElements` to replace it entirely, within the `angular-test-ids/require-test-id` rule configuration.
Add `"angular-test-ids"` to the `plugins` array in your `.eslintrc` file.
Ensure that the `parser` option in your `.eslintrc` (specifically for HTML files) is set to `"@angular-eslint/template-parser"`.
Verify that option names like `attribute`, `overrideElements`, and `addElements` are spelled correctly and enclosed in double quotes as JSON object keys.