| 1 | # Disallow identical titles (`no-identical-title`)
|
|---|
| 2 |
|
|---|
| 3 | Having identical titles for two different tests or test suites may create
|
|---|
| 4 | confusion. For example, when a test with the same title as another test in the
|
|---|
| 5 | same test suite fails, it is harder to know which one failed and thus harder to
|
|---|
| 6 | fix.
|
|---|
| 7 |
|
|---|
| 8 | ## Rule Details
|
|---|
| 9 |
|
|---|
| 10 | This rule looks at the title of every test and test suites. It will report when
|
|---|
| 11 | two test suites or two test cases at the same level of a test suite have the
|
|---|
| 12 | same title.
|
|---|
| 13 |
|
|---|
| 14 | The following patterns are considered warnings:
|
|---|
| 15 |
|
|---|
| 16 | ```js
|
|---|
| 17 | describe('foo', () => {
|
|---|
| 18 | it('should do bar', () => {});
|
|---|
| 19 | it('should do bar', () => {}); // Has the same title as the previous test
|
|---|
| 20 |
|
|---|
| 21 | describe('baz', () => {
|
|---|
| 22 | // ...
|
|---|
| 23 | });
|
|---|
| 24 |
|
|---|
| 25 | describe('baz', () => {
|
|---|
| 26 | // Has the same title as a previous test suite
|
|---|
| 27 | // ...
|
|---|
| 28 | });
|
|---|
| 29 | });
|
|---|
| 30 | ```
|
|---|
| 31 |
|
|---|
| 32 | These patterns would not be considered warnings:
|
|---|
| 33 |
|
|---|
| 34 | ```js
|
|---|
| 35 | describe('foo', () => {
|
|---|
| 36 | it('should do foo', () => {});
|
|---|
| 37 | it('should do bar', () => {});
|
|---|
| 38 |
|
|---|
| 39 | // Has the same name as a parent test suite, which is fine
|
|---|
| 40 | describe('foo', () => {
|
|---|
| 41 | // Has the same name as a test in a parent test suite, which is fine
|
|---|
| 42 | it('should do foo', () => {});
|
|---|
| 43 | it('should work', () => {});
|
|---|
| 44 | });
|
|---|
| 45 |
|
|---|
| 46 | describe('baz', () => {
|
|---|
| 47 | // Has the same title as a previous test suite
|
|---|
| 48 | // Has the same name as a test in a sibling test suite, which is fine
|
|---|
| 49 | it('should work', () => {});
|
|---|
| 50 | });
|
|---|
| 51 | });
|
|---|
| 52 | ```
|
|---|