jestjs/jest · error · Error
Missing second argument. It must be a callback function.
Error message
Missing second argument. It must be a callback function.
What it means
describe() requires exactly two arguments: a description and a callback. Env.ts:399-403 throws when the second argument (specDefinitions) is undefined — i.e. describe was called with only a name. This catches a common typo before the suite is built.
Source
Thrown at packages/jest-jasmine2/src/jasmine/Env.ts:400
id: getNextSuiteId(),
description,
parentSuite: currentDeclarationSuite,
throwOnExpectationFailure,
getTestPath() {
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();
}View on GitHub (pinned to f49721c78e)
Solutions
- Provide the required callback: describe('name', () => { ... }).
- If you intended a placeholder suite, use an empty callback describe('name', () => {}) or skip it.
- Remove the incomplete describe line entirely if it is leftover scaffolding.
Example fix
// before
describe('calculator');
// after
describe('calculator', () => { it('adds', () => {}); }); Defensive patterns
Strategy: type-guard
Validate before calling
function assertDescribeArgs(name: unknown, fn: unknown) {
if (fn === undefined) throw new Error('describe requires a callback as the 2nd argument');
} Type guard
function isDescribeArgs(args: [unknown, unknown]): args is [string, () => void] {
return args.length >= 2 && typeof args[1] === 'function';
} Prevention
- Use TypeScript so describe signature mismatches surface at compile time.
- Run a quick lint that flags describe calls with < 2 arguments.
When it happens
Trigger: Calling `describe('name')` with no callback, or `describe('name', undefined)`. The check at Env.ts:399 (`specDefinitions === undefined`) triggers the throw at line 400.
Common situations: Incomplete test draft left in a file; refactor that removed the body but left the describe line; copy-paste missing the callback; accidental semicolon terminating the call.
Related errors
- Invalid second argument, ${specDefinitions}. It must be a ca
- describe does not expect any arguments
- Missing second argument. It must be a callback function. Per
- Invalid second argument, ${fn}. It must be a callback functi
- Tests cannot be nested. Test "${spec.description}" cannot ru
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/d606d900a1c76804.json.
Report an issue: GitHub.