no-assert-in-hook

July 2, 2026 ยท View on GitHub

๐Ÿ“ Disallow assertions inside hooks.

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

Hooks (before, after, beforeEach, afterEach) are for setup and teardown, not verification. When an assertion fails inside a hook, the runner reports it as a hook failure attributed to every test the hook applies to, rather than as a single focused test failure, which makes the cause harder to locate. Put assertions inside the tests that depend on them.

This is the hook counterpart of no-assert-in-describe.

This rule is off by default, since asserting a precondition in a hook to fail fast is a defensible pattern. Enable it if you prefer all assertions to live in tests.

Examples

import {beforeEach, it} from 'node:test';
import assert from 'node:assert';

// โŒ
beforeEach(() => {
	assert.ok(database.isConnected);
});

// โœ…
it('reads a record', () => {
	assert.ok(database.isConnected);
	// โ€ฆ
});