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);
// โฆ
});