Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-test-selectors

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-test-selectors

Makes sure test DOM attributes (e.g. data-test-id) are added to interactive DOM elements.

  • 1.0.0
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

eslint-plugin-test-selectors

Enforces that a data-test-id attribute is present on interactive DOM elements to help with UI testing.

  • <button>Download</button>
  • <button data-test-id="download-button">Download</button>

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-test-selectors:

$ npm install eslint-plugin-test-selectors --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-test-selectors globally.

Usage

Add test-selectors to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "test-selectors"
    ]
}

By default, all of these rules are enabled:

You can selectively disable individual rules in the rules section of your .eslintrc configuration:

{
    "rules": {
        "test-selectors/anchor": ["error", "never"]
    }
}

Custom attributes

If you don't want to use the default data-test-id attribute, you can selectively override it in each rule definition:

{
    "rules": {
        "test-selectors/onChange": ["error", "always", { "testAttribute": "data-some-custom-attribute" }]
    }
}

Supported Rules

  • test-selectors/anchor
  • test-selectors/button
  • test-selectors/input
  • test-selectors/onChange
  • test-selectors/onClick
  • test-selectors/onKeyDown
  • test-selectors/onKeyUp

Further Reading

If you don't want these test attributes added in production, you can use something like babel-plugin-jsx-remove-data-test-id

Why data attributes and not id or class? Check out some of the following:

Keywords

FAQs

Package last updated on 04 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc