Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 1.46 KB

no-identical-tests.md

File metadata and controls

54 lines (41 loc) · 1.46 KB

Disallow identical tests (eslint-plugin/no-identical-tests)

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

Duplicate test cases can cause confusion, can be hard to detect manually in a long file, and serve no purpose.

As of ESLint v9, ESLint attempts to detect and disallow duplicate tests.

Rule Details

This rule detects duplicate test cases.

Examples of incorrect code for this rule:

/* eslint eslint-plugin/no-identical-tests: error */

new RuleTester().run('foo', bar, {
  valid: [
    'foo',
    'foo', // duplicate of previous
  ],
  invalid: [
    {
      code: 'bar',
      errors: [{ messageId: 'my-message', type: 'CallExpression' }],
    },
    {
      code: 'bar',
      errors: [{ messageId: 'my-message', type: 'CallExpression' }],
    }, // duplicate of previous
  ],
});

Examples of correct code for this rule:

/* eslint eslint-plugin/no-identical-tests: error */

new RuleTester().run('foo', bar, {
  valid: ['foo', 'bar'],
  invalid: [
    {
      code: 'baz',
      errors: [{ messageId: 'my-message', type: 'CallExpression' }],
    },
  ],
});