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
The `describe()` function requires exactly two arguments: a description and a callback. If the callback (specDefinitions) is undefined — i.e. describe was called with only one argument or the second argument was explicitly omitted — Env.describe throws this Error at Env.ts:401 before any suite is created.
Solutions
- Add the missing callback: `describe('my suite', () => { ... })`.
- If the suite body is not yet written, use an empty arrow function as a placeholder.
- Check that any variable passed as the callback is defined before the describe call.
Example fix
// before
describe('my suite');
// after
describe('my suite', () => {
it('does something', () => {});
}); Defensive patterns
Strategy: type-guard
Validate before calling
// Wrap describe to enforce the callback at the call site.
function safeDescribe(name: string, fn?: () => void) {
if (typeof fn !== 'function') {
throw new TypeError(`describe('${name}') requires a callback function.`);
}
return describe(name, fn);
} Type guard
function isDescribeCallback(value: unknown): value is () => void {
return typeof value === 'function';
} Prevention
- Always provide a callback to describe, even an empty arrow function for stubs.
- Use TypeScript types that require the second parameter.
- Enable eslint-plugin-jest to catch malformed describe calls.
When it happens
Trigger: Calling `describe('my suite')` with no second argument, or `describe('my suite', undefined)`. The guard at Env.ts:400 checks `specDefinitions === undefined`.
Common situations: Incomplete/partially written test; copy-paste where the callback was dropped; a refactor that extracted the callback into a variable that is undefined at call time; a conditional that sometimes omits the callback.
Related errors
- describe does not expect any arguments
- Invalid second argument
- Invalid first argument. It must be a callback function.
- Invalid second argument
- Missing second argument. It must be a callback function…
AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10).
Data as JSON: /api/errors/d606d900a1c76804.
Report an issue: GitHub.
Appendix: source
Thrown at packages/jest-jasmine2/src/jasmine/Env.ts:401
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 8e6d128e4a)