Skip to content

Commit

Permalink
docs: modernize rule doc for no-identical-tests (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Jul 8, 2022
1 parent bd9a650 commit d6d79aa
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions docs/rules/no-identical-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,34 @@

⚒️ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#--fix) can automatically fix some of the problems reported by this rule.

When a rule has a lot of tests, it's sometimes difficult to tell if any tests are duplicates. This rule would warn if any test cases have the same properties.
Duplicate test cases can cause confusion, can be hard to detect manually in a long file, and serve no purpose.

As of [ESLint v9](https://github.com/eslint/rfcs/tree/main/designs/2021-stricter-rule-test-validation#disallow-identical-test-cases), ESLint attempts to detect and disallow duplicate tests.

## Rule Details

This rule detects duplicate test cases.

Examples of **incorrect** code for this rule:

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

new RuleTester().run('foo', bar, {
valid: [{ code: 'foo' }, { code: 'foo' }],
invalid: [],
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
],
});
```

Expand All @@ -25,11 +41,12 @@ Examples of **correct** code for this rule:
/* eslint eslint-plugin/no-identical-tests: error */

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

## When Not To Use It

If you want to allow identical tests, do not enable this rule.

0 comments on commit d6d79aa

Please sign in to comment.