davidcalhoun / eslint-plugin-test-selectors

Enforces that data-test-id attributes are added to interactive DOM elements (JSX) to help with UI testing. JSX only.
28 stars 14 forks source link

Bug with testAttribute error messages #7

Closed mahammedzkhan closed 4 years ago

mahammedzkhan commented 4 years ago

I've added this plugin to our projects with the following settings:

rules: [
"test-selectors/onChange": [
      "warn",
      "always",
      {
        "testAttribute": "data-testid"
      }
    ],
]

Is it possible to set the testAttribute for all rules? Because I don't think there's a scenario where you use a different testAttribute for onChange and for button.

davidcalhoun commented 4 years ago

Hello @mahammedzkhan - it looks like you just enabled that custom test selector for the onChange handler rule. There's currently no way to turn on that custom selector for all rules unfortunately. If you want to enable that custom attribute for all rules, your ESLint config will look something like this:

{
    "rules": {
        "test-selectors/anchor": ["warn", "always", { "testAttribute": "data-testid" }],
        "test-selectors/button": ["warn", "always", { "testAttribute": "data-testid" }],
        "test-selectors/input": ["warn", "always", { "testAttribute": "data-testid" }],
        "test-selectors/onChange": ["warn", "always", { "testAttribute": "data-testid" }],
        "test-selectors/onClick": ["warn", "always", { "testAttribute": "data-testid" }],
        "test-selectors/onKeyDown": ["warn", "always", { "testAttribute": "data-testid" }],
        "test-selectors/onKeyUp": ["warn", "always", { "testAttribute": "data-testid" }]
    }
}