Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: modernize rule doc for no-identical-tests #265

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.