Skip to content

TypeScript · testing

no-tautological-expect

eslint:no-tautological-expect

Disallow an assertion whose operands are all literals; its outcome is fixed before the code runs, so it can never fail.

Default
error
Fix
none
Languages
typescript

Why

An assertion determined entirely by literals does not observe the code under test and can keep passing after that code is removed.

Fix

Assert on a value produced by the behavior under test, or remove the assertion.

Before / after

Executed by this rule’s unit tests.

Before

Do not compare identical literals

src/add.test.ts · focus
it('works', () => { expect(true).toBe(true); });

After

Assert on a produced value

src/add.test.ts · focus
it('adds', () => { expect(add(1, 1)).toBe(2); });

Limits

  • Only direct supported `expect` matcher calls in recognized test files are inspected.

Message IDs

tautologicalComparisontautologicalMatcher