no-parent-test-context
July 3, 2026 ยท View on GitHub
๐ Disallow references to parent test contexts inside subtests.
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
๐ก This rule is manually fixable by editor suggestions.
Each t.test() callback receives its own test context. Referencing the parent context inside the child callback attaches lifecycle-scoped work to the wrong test: mocks restore with the parent, plan() counts on the parent, t.assert assertions are tied to the parent, and nested subtests are created under the parent.
This rule reports references to an outer test context binding from inside an inline subtest callback. Use the child callback's own context parameter instead. Only inline test/subtest callback chains are analyzed; non-inline callbacks such as test('parent', helper) or t.test('child', helper) are not analyzed. References inside nested regular test callbacks are treated as a new test boundary and are not reported.
Examples
import test from 'node:test';
// โ
test('parent', async t => {
await t.test('child', () => {
t.mock.method(fs, 'readFileSync', () => '{}');
});
});
// โ
test('parent', async t => {
await t.test('child', t2 => {
t2.mock.method(fs, 'readFileSync', () => '{}');
});
});