Skip to main content
interlace
Plugin: react-featuresRules

no-default-test-id

data-testid must be consumer-provided — no runtime default value (R5)

Part of: componentApi preset (opt-in — not in recommended)

data-testid must be type-required and consumer-provided. A runtime default contradicts the type-level requirement and silently masks consumer omissions — the consumer believes they are covered by the type system, but the default lets the component render with a generic test-id that collides in multi-instance tests.

Why This Matters

IssueImpactSolution
Silent maskingConsumer omits data-testid; default fires instead of a type errorRemove the default; require it at the type level
CollisionMultiple instances share the same default test-idEach consumer must provide a unique, descriptive id

Examples

Incorrect

function Button({ "data-testid": testId = "button", ...props }) {
  return <button data-testid={testId} {...props} />;
}

Correct

function Button({ "data-testid": testId, ...props }: { "data-testid": string }) {
  return <button data-testid={testId} {...props} />;
}

Auto-fix

This rule provides an auto-fix that removes the default value, leaving the bare binding identifier.

Configuration

// eslint.config.mjs
export default [
  {
    rules: {
      "react-features/no-default-test-id": "error",
    },
  },
];

This rule is part of eslint-plugin-react-features.

Use this rule

npm install -D oxlint-plugin-react-features
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-react-features"],  "rules": {    "react-features/no-default-test-id": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-react-features'],    rules: {      'react-features/no-default-test-id': 'error',    },  },});

oxlint-plugin-react-features re-exports eslint-plugin-react-features/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.