Skip to content

TypeScript · testing

no-conditional-in-test

eslint:no-conditional-in-test

Disallow test conditionals that can skip a runtime assertion or exit the test before one runs.

Default
error
Fix
none
Languages
typescript

Why

A branch can skip the assertion that gives a test its meaning, allowing unexpected inputs to pass silently.

Fix

Split each path into a separate test or use a parameterized case table with unconditional assertions.

Before / after

Executed by this rule’s unit tests.

Before

A branch can skip the assertion

src/component.test.ts · focus
it('fails with if', () => { if (ready) { expect(value).toBe(1); } });

After

A test always executes its assertion

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

Limits

  • The rule exempts lifecycle hooks, nested helpers, and narrow guards whose outcome is pinned by a preceding assertion.

Message IDs

noConditionalInTest