no-conditional-in-test

July 2, 2026 ยท View on GitHub

๐Ÿ“ Disallow conditional logic inside tests.

๐Ÿšซ This rule is disabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

A test should exercise one specific scenario and behave the same way on every run. Conditional logic (if, switch, or a ternary) inside a test body means different code runs depending on the environment or input, which makes failures harder to reproduce and can hide assertions that never execute. Usually the branches should be separate tests, or the value should be computed before the test.

This rule reports if/switch statements and ternary expressions inside a test or hook body. Conditionals inside a describe body are about registering tests and are covered by no-conditional-tests instead.

This is a broad, opinionated rule, so it is off by default. For the narrower case of an assertion that may never run, see no-conditional-assertion.

Examples

import test from 'node:test';

// โŒ
test('title', () => {
	if (condition) {
		assert.ok(value);
	}
});

// โœ…
test('title with condition', () => {
	assert.ok(value);
});

// โœ…
test('title without condition', () => {
	assert.ok(other);
});