Skip to content

ESLINT / TESTING

duplicate-test-body

eslint:duplicate-test-body

Disallow substantial sibling tests with the same body shape; express their differing inputs as a parameterized case table.

Default
error
Fix
none
Languages
typescript

WHY IT EXISTS

Rationale

Copy-pasted test bodies hide the cases that differ and allow equivalent assertions to drift independently.

WHAT TO DO

Remediation

Move the varying inputs and expected values into a case table consumed by `test.each(...)` or `it.each(...)`.

EXECUTABLE EXAMPLES

Accepted and reported examples

Reported

Sibling tests repeat the same body

src/user.test.ts · focus
test('accepts a', () => { const result = parse('a'); expect(result.ok).toBe(true); expect(result.value).toBe('a'); });
test('accepts b', () => { const result = parse('b'); expect(result.ok).toBe(true); expect(result.value).toBe('b'); });

Accepted

A case table shares one test body

src/user.test.ts · focus
test.each(['a', 'b'])('parses %s', (value) => { const x = parse(value); expect(x.ok).toBe(true); expect(x.value).toBe(value); });

BOUNDARIES

Known limitations

  • The rule compares substantial sibling tests within one suite and skips inline snapshots and materially different comments.

DIAGNOSTICS

Message IDs

duplicateTestBody