no-nested-tests
July 2, 2026 ยท View on GitHub
๐ Disallow tests and suites nested inside a test body.
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
Defining a test or suite inside a test body does not register a proper subtest. Use the test context's t.test() for subtests, and group tests with describe() instead.
Grouping tests inside a describe()/suite(), and nesting suites, is fine โ this rule only flags tests and suites declared inside a test()/it() body.
Examples
import test, {describe, it} from 'node:test';
// โ
test('outer', () => {
test('inner', () => {});
});
// โ
test('outer', () => {
describe('inner', () => {});
});
// โ
Use a subtest
test('outer', async t => {
await t.test('inner', () => {});
});
// โ
Suites group tests and nested suites
describe('group', () => {
it('a', () => {});
describe('nested', () => {
it('b', () => {});
});
});