jestjs/jest · error · TypeError
Invalid second argument, ${specDefinitions}. It must be a ca
Error message
Invalid second argument, ${specDefinitions}. It must be a callback function. What it means
describe()'s second argument must be a function. Env.ts:404-408 throws a TypeError (note: TypeError, not Error) when specDefinitions is defined but not a function — e.g. an object, array, string, or config object mistakenly passed as the body. The interpolated value in the message helps spot what was actually passed.
Source
Thrown at packages/jest-jasmine2/src/jasmine/Env.ts:405
return j$.testPath;
},
});
return suite;
};
this.describe = function (
description: Circus.TestNameLike,
specDefinitions,
) {
const suite = suiteFactory(description);
if (specDefinitions === undefined) {
throw new Error(
'Missing second argument. It must be a callback function.',
);
}
if (typeof specDefinitions !== 'function') {
throw new TypeError(
`Invalid second argument, ${specDefinitions}. It must be a callback function.`,
);
}
if (specDefinitions.length > 0) {
throw new Error('describe does not expect any arguments');
}
if (currentDeclarationSuite.markedPending) {
suite.pend();
}
if (currentDeclarationSuite.markedTodo) {
// @ts-expect-error TODO Possible error: Suite does not have todo method
suite.todo();
}
addSpecsToSuite(suite, specDefinitions);
return suite;
};
this.xdescribe = function (description, specDefinitions) {View on GitHub (pinned to f49721c78e)
Solutions
- Pass a function as the second argument: describe('name', () => { ... }).
- Inspect the interpolated value in the message to identify which non-function was passed and fix the binding.
- If wrapping describe, ensure your wrapper forwards the callback in the correct position.
Example fix
// before — object passed instead of callback
describe('calculator', { tests: true });
// after
describe('calculator', () => { it('adds', () => {}); }); Defensive patterns
Strategy: type-guard
Validate before calling
function assertDescribeFn(fn: unknown) {
if (typeof fn !== 'function') throw new TypeError('describe callback must be a function');
} Type guard
function isFn(v: unknown): v is Function { return typeof v === 'function'; }
if (!isFn(specDefinitions)) throw new TypeError('describe callback missing'); Prevention
- Type your test helpers so non-function describe bodies fail at compile time.
- Lint for describe with a non-function second argument.
When it happens
Trigger: Calling `describe('name', someObject)`, `describe('name', [...])`, or `describe('name', 'does things')`. The `typeof specDefinitions !== 'function'` check at Env.ts:404 fires the TypeError at line 405.
Common situations: Passing a configuration object instead of a function; destructuring mistake leaving the wrong binding as the second arg; tools that wrap describe and forward the wrong parameter.
Related errors
- Missing second argument. It must be a callback function.
- describe does not expect any arguments
- Invalid second argument, ${fn}. It must be a callback functi
- Missing second argument. It must be a callback function. Per
- Tests cannot be nested. Test "${spec.description}" cannot ru
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/3644f41f6ffd5f4e.json.
Report an issue: GitHub.