Skip to content

Commit ed937f9

Browse files
committed
docs: modernize rule doc for no-identical-tests
1 parent 951d208 commit ed937f9

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

docs/rules/no-identical-tests.md

+26-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,34 @@
44

55
⚒️ 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.
66

7-
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.
7+
Duplicate test cases can cause confusion, can be hard to detect manually in a long file, and serve no purpose.
8+
9+
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.
810

911
## Rule Details
1012

13+
This rule detects duplicate test cases.
14+
1115
Examples of **incorrect** code for this rule:
1216

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

1620
new RuleTester().run('foo', bar, {
17-
valid: [{ code: 'foo' }, { code: 'foo' }],
18-
invalid: [],
21+
valid: [
22+
'foo',
23+
'foo', // duplicate of previous
24+
],
25+
invalid: [
26+
{
27+
code: 'bar',
28+
errors: [{ messageId: 'my-message', type: 'CallExpression' }],
29+
},
30+
{
31+
code: 'bar',
32+
errors: [{ messageId: 'my-message', type: 'CallExpression' }],
33+
}, // duplicate of previous
34+
],
1935
});
2036
```
2137

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

2743
new RuleTester().run('foo', bar, {
28-
valid: [{ code: 'foo' }, { code: 'bar' }],
29-
invalid: [],
44+
valid: ['foo', 'bar'],
45+
invalid: [
46+
{
47+
code: 'baz',
48+
errors: [{ messageId: 'my-message', type: 'CallExpression' }],
49+
},
50+
],
3051
});
3152
```
32-
33-
## When Not To Use It
34-
35-
If you want to allow identical tests, do not enable this rule.

0 commit comments

Comments
 (0)