no-standalone-assert
July 2, 2026 ยท View on GitHub
๐ Disallow assertions outside of a test.
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
An assertion written at the top level of a test file runs once when the module is loaded, not as part of any test. A failure there aborts the whole file before the tests run, and a passing one is never attributed to a test. It almost always means the assertion was meant to be inside a test or hook.
This rule reports node:assert assertions at the module top level of a file that imports node:test. Assertions inside a describe/suite body are handled by no-assert-in-describe, and assertions inside helper functions are allowed (a helper may be called from a test). Top-level assertions in modules that do not import node:test are left alone, since they are legitimate runtime guards.
Examples
import test from 'node:test';
import assert from 'node:assert/strict';
// โ
assert.ok(setupSucceeded);
// โ
test('setup succeeds', () => {
assert.ok(setupSucceeded);
});