consistent-test-context-name

July 23, 2026 ยท View on GitHub

๐Ÿ“ Enforce a consistent name for the test context parameter.

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

The test and subtest callbacks receive a test context object, conventionally named t (test('โ€ฆ', t => {})). Using a consistent name keeps t.assert, t.mock, t.test, and t.plan recognizable across a codebase.

This rule reports a test/it (or subtest) callback whose first parameter is named something other than the configured name, including one with a default value ((context = โ€ฆ) => {}). Callbacks with no parameter, or that destructure the context, are left alone.

Options

  • name (string, default 't') โ€” the required parameter name.
{
	'node-test/consistent-test-context-name': [
		'error',
		{
			name: 't'
		}
	]
}

Examples

import test from 'node:test';

// โŒ
test('reads a file', context => {
	context.assert.ok(result);
});

// โœ…
test('reads a file', t => {
	t.assert.ok(result);
});