max-assertions

July 15, 2026 ยท View on GitHub

๐Ÿ“ Enforce a maximum number of assertions in a test.

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

A test that makes many assertions is usually checking several things at once and is harder to read and debug when it fails. Splitting it into focused tests makes each failure point clear.

This rule reports a test whose body makes more than the allowed number of assertions. Assertions in a subtest (t.test(โ€ฆ)) are counted against that subtest, not its parent.

Examples

import test from 'node:test';
import assert from 'node:assert/strict';

// โŒ
test('user', () => {
	assert.strictEqual(user.name, 'Ada');
	assert.strictEqual(user.age, 36);
	assert.strictEqual(user.email, 'ada@example.com');
	assert.ok(user.active);
	assert.ok(user.admin);
	assert.ok(user.verified);
});

// โœ…
test('user identity', () => {
	assert.strictEqual(user.name, 'Ada');
	assert.strictEqual(user.email, 'ada@example.com');
});

test('user permissions', () => {
	assert.ok(user.admin);
	assert.ok(user.verified);
});

Options

max

Type: number
Default: 5

The maximum number of assertions allowed in a test.

/* eslint
	node-test/max-assertions: [
		'error',
		{
			max: 3
		}
	]
*/
import test from 'node:test';
import assert from 'node:assert/strict';

// โŒ
test('user', () => {
	assert.strictEqual(user.name, 'Ada');
	assert.strictEqual(user.age, 36);
	assert.ok(user.active);
	assert.ok(user.admin);
});