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', () => {});
	});
});