eslint-node-test
July 13, 2026 Β· View on GitHub
ESLint rules for the Node.js built-in test runner (
node:test)
This plugin helps you avoid common mistakes and write more consistent tests with node:test, the test runner built into Node.js.
Install
npm install --save-dev eslint eslint-node-test
Requires ESLint >=10.4, flat config, and ESM.
Usage
Use a preset config or configure each rule in eslint.config.js.
import eslintNodeTest from 'eslint-node-test';
import {defineConfig} from 'eslint/config';
export default defineConfig([
eslintNodeTest.configs.recommended,
]);
Or configure rules individually:
import eslintNodeTest from 'eslint-node-test';
import {defineConfig} from 'eslint/config';
export default defineConfig([
{
plugins: {
'node-test': eslintNodeTest,
},
rules: {
'node-test/no-only-test': 'error',
'node-test/no-identical-title': 'error',
},
},
]);
The rules only activate in files that import from node:test (and assertion rules also activate for Node's built-in assert module), so you can safely apply the plugin across your whole project.
Rules
πΌ Configurations enabled in.
β
Set in the recommended configuration.
βοΈ Set in the unopinionated configuration.
π§ Automatically fixable by the --fix CLI option.
π‘ Manually fixable by editor suggestions.
| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | π§ | π‘ |
|---|---|---|---|---|
| assertion-arguments | Enforce the correct number of arguments for node:assert assertions. | β βοΈ | ||
| consistent-assert-style | Enforce a consistent truthiness assertion style. | β | π§ | |
| consistent-assert-throws-callback-style | Enforce a consistent body style for assert.throws() arrow callbacks. | π§ | ||
| consistent-modifier-style | Enforce a consistent style for test modifiers. | |||
| consistent-test-context-name | Enforce a consistent name for the test context parameter. | β βοΈ | ||
| consistent-test-filename | Enforce a consistent test file name pattern. | |||
| consistent-test-it | Enforce consistent use of test or it. | |||
| hooks-order | Enforce a consistent order of hook declarations. | β βοΈ | π§ | |
| max-assertions | Enforce a maximum number of assertions in a test. | |||
| max-nested-describe | Enforce a maximum depth for nested describe blocks. | β | ||
| no-assert-in-describe | Disallow assertions directly inside a describe body. | β | ||
| no-assert-in-hook | Disallow assertions inside hooks. | |||
| no-assert-match-string | Disallow strings as the regexp argument of assert.match()/assert.doesNotMatch(). | β βοΈ | π‘ | |
| no-assert-throws-async | Disallow passing an async function to assert.throws()/assert.doesNotThrow(). | β βοΈ | π‘ | |
| no-assert-throws-call | Disallow calling the function passed to assert.throws(). | β βοΈ | π‘ | |
| no-assert-throws-multiple-statements | Disallow multiple statements in assert.throws()/assert.rejects() callbacks. | β | ||
| no-assert-throws-string | Disallow a string as the error matcher of assert.throws()/assert.rejects(). | β βοΈ | π‘ | |
| no-async-describe | Disallow async describe callbacks. | β βοΈ | ||
| no-async-fn-without-await | Disallow async test/hook functions that have no await expression. | β βοΈ | π‘ | |
| no-callback-and-promise | Disallow a test or hook from using both a callback and a Promise. | β βοΈ | ||
| no-commented-tests | Disallow commented-out tests. | |||
| no-compound-assertion | Disallow compound truthiness assertions. | β βοΈ | π§ | |
| no-conditional-assertion | Disallow assertions inside conditional code within a test. | β βοΈ | ||
| no-conditional-in-test | Disallow conditional logic inside tests. | |||
| no-conditional-tests | Disallow conditionally registering tests, suites, and hooks. | β | ||
| no-conflicting-modifiers | Disallow conflicting test modifiers. | β βοΈ | ||
| no-constant-assertion | Disallow assertions with constant outcomes. | β βοΈ | ||
| no-done-callback | Disallow callback (done) parameters in tests and hooks. | |||
| no-duplicate-assertions | Disallow adjacent duplicate assertions. | β βοΈ | ||
| no-duplicate-hooks | Disallow duplicate hooks within the same scope. | β | ||
| no-duplicate-mock-timers-enable | Disallow enabling mock timers more than once without resetting them. | β βοΈ | ||
| no-duplicate-plan | Disallow setting a test plan more than once in the same test. | β βοΈ | ||
| no-expect-failure-without-reason | Require a reason when marking a test or suite as expected to fail. | β | ||
| no-export | Disallow exports from test files. | β | ||
| no-identical-assertion-arguments | Disallow comparing a value to itself in an assertion. | β βοΈ | ||
| no-identical-title | Disallow identical test titles within the same scope. | β βοΈ | ||
| no-import-test-files | Disallow imports of Node.js test files. | β βοΈ | ||
| no-incorrect-deep-equal | Disallow deepEqual/deepStrictEqual (and their notDeep* variants) when comparing with primitives. | β βοΈ | π§ | |
| no-incorrect-strict-equal | Disallow strictEqual/equal (and their not* variants) when comparing with an object or array literal. | β βοΈ | π§ | |
| no-late-test-activity | Disallow test activity inside detached asynchronous callbacks. | β βοΈ | π§ | |
| no-loop-static-title | Disallow a static test or suite title inside a loop. | β βοΈ | ||
| no-misused-concurrency | Disallow the concurrency option on a test without subtests. | β βοΈ | ||
| no-misused-context-hook | Disallow context hooks without runnable subtests. | β βοΈ | ||
| no-mock-module-after-import | Disallow mocking a module after statically importing it. | β βοΈ | ||
| no-mock-timers-destructured-import | Disallow destructured timer imports when using mock.timers. | β βοΈ | ||
| no-nested-tests | Disallow tests and suites nested inside a test body. | β βοΈ | ||
| no-only-test | Disallow the .only test modifier. | β βοΈ | π‘ | |
| no-parent-test-context | Disallow references to parent test contexts inside subtests. | β βοΈ | π‘ | |
| no-process-chdir-in-test | Disallow changing the working directory inside tests. | β | ||
| no-process-env-mutation | Disallow mutating process.env inside tests. | β | ||
| no-process-exit-in-test | Disallow process exit control in test files. | β βοΈ | ||
| no-skip-test | Disallow the .skip test modifier. | β | π‘ | |
| no-skip-without-reason | Require a reason when skipping or marking a test as todo. | |||
| no-skip-without-return | Disallow t.skip()/t.todo() without returning afterwards. | β | π‘ | |
| no-sleep-in-test | Disallow sleeping in tests with setTimeout. | |||
| no-snapshot-in-loop | Disallow snapshot assertions inside loop bodies. | |||
| no-standalone-assert | Disallow assertions outside of a test. | β βοΈ | ||
| no-test-global-configuration | Disallow process-wide node:test configuration inside tests. | β | ||
| no-test-inside-hook | Disallow defining tests and suites inside a hook. | β βοΈ | ||
| no-test-return-statement | Disallow returning a concrete non-Promise value from a test or hook. | β | ||
| no-todo-test | Disallow the .todo test modifier. | π‘ | ||
| no-unawaited-promise-assertion | Disallow assertions inside unawaited Promise callbacks. | β βοΈ | π§ | |
| no-unawaited-rejects | Require assert.rejects()/assert.doesNotReject() to be awaited or returned. | β βοΈ | π§ | |
| no-unawaited-subtest | Require subtests created with the test context to be awaited or returned. | β | π§ | |
| no-unknown-test-options | Disallow unknown options in test and hook option objects. | β | ||
| no-unneeded-async-rejects-callback | Disallow unneeded async callbacks passed to assert.rejects(). | π‘ | ||
| no-useless-assertion | Disallow assert.doesNotThrow() and assert.doesNotReject(). | β | ||
| prefer-assert-match | Prefer assert.match()/assert.doesNotMatch() over asserting RegExp#test() / String#match() results. | β βοΈ | π§ | |
| prefer-assert-throws | Prefer assert.throws()/assert.rejects() over try/catch with an assertion. | β | ||
| prefer-async-await | Prefer async/await over returning a Promise. | β | ||
| prefer-context-mock | Prefer the test context t.mock over the global mock. | β | ||
| prefer-diagnostic | Prefer the test context diagnostic() over console inside tests. | π‘ | ||
| prefer-equality-assertion | Prefer an equality assertion over a truthiness assertion on a comparison. | β βοΈ | π§ | |
| prefer-hooks-on-top | Require hooks to be declared before the tests in their scope. | β | ||
| prefer-lowercase-title | Enforce lowercase test titles. | π§ | ||
| prefer-mock-accessor | Prefer mock.getter() and mock.setter() over mock.method() with accessor options. | β | π§ | |
| prefer-mock-call-count | Prefer mock.callCount() over mock.calls.length. | β βοΈ | π§ | |
| prefer-mock-method | Prefer mock.method() over assigning mock.fn() to an object property. | β | π‘ | |
| prefer-strict-assert | Prefer strict assertion methods over their legacy loose counterparts. | β βοΈ | π§ | |
| prefer-test-context-assert | Prefer the test context t.assert over the imported node:assert. | β | π‘ | |
| prefer-todo | Prefer .todo for empty placeholder tests. | β | π‘ | |
| require-assertion | Require that each test contains at least one assertion. | β | ||
| require-await-concurrent-subtests | Require subtests created in a loop callback to be awaited. | β βοΈ | ||
| require-context-assert-with-plan | Require assertions to use the test context when the test sets a plan. | β βοΈ | ||
| require-hook | Require setup and teardown code to be inside a hook. | |||
| require-mock-timers-advance | Require mock timers to be advanced after enabling timer APIs. | β | ||
| require-mock-timers-apis | Require an explicit apis option when enabling mock.timers. | β βοΈ | ||
| require-throws-expectation | Require an error matcher for assert.throws()/assert.rejects(). | β βοΈ | ||
| require-throws-validator-return-true | Require validator functions in assert.throws()/assert.rejects() to return true. | β βοΈ | ||
| require-top-level-describe | Require tests and hooks to be inside a top-level describe. | |||
| test-title | Require tests to have a title. | β | π§ | |
| test-title-format | Require test titles to match a configured pattern. | |||
| valid-describe-callback | Enforce valid describe callbacks. | β βοΈ | ||
| valid-test-tags | Require valid test tags. | β βοΈ | π§ |
Preset configs
This plugin exports these configs:
recommendedβ Enables the recommended rules.unopinionatedβ A subset ofrecommendedwith only the most uncontroversial rules.allβ Enables every rule (not recommended for general use; useful to discover new rules).
import eslintNodeTest from 'eslint-node-test';
import {defineConfig} from 'eslint/config';
export default defineConfig([
eslintNodeTest.configs.recommended,
]);
Related
- eslint-plugin-unicorn β Lots of awesome ESLint rules.
- eslint-package-json β Powerful ESLint rules for
package.json. - eslint-plugin-ava β ESLint rules for AVA.
- test-extras β Assertions and utilities that make
node:testbetter.