jestjs/jest · error · Error
Missing second argument. It must be a callback function. Per
Error message
Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.
What it means
it()/test() requires a callback as the second argument. Env.ts:554-558 throws when fn is undefined, with a hint pointing to test.todo for placeholder tests. This distinguishes 'I forgot the body' from 'I want a placeholder' and nudges toward the right API.
Source
Thrown at packages/jest-jasmine2/src/jasmine/Env.ts:555
return spec;
function specResultCallback(result: SpecResult) {
clearResourcesForRunnable(spec.id);
currentSpec = null;
reporter.specDone(result);
}
function specStarted(spec: Spec) {
currentSpec = spec;
defaultResourcesForRunnable(spec.id, suite.id);
reporter.specStarted(spec.result);
}
};
this.it = function (description, fn, timeout) {
description = convertDescriptorToString(description);
if (fn === undefined) {
throw new Error(
'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.',
);
}
if (typeof fn !== 'function') {
throw new TypeError(
`Invalid second argument, ${fn}. It must be a callback function.`,
);
}
const spec = specFactory(
description,
fn,
currentDeclarationSuite,
timeout,
);
if (currentDeclarationSuite.markedPending) {
spec.pend();
}
View on GitHub (pinned to f49721c78e)
Solutions
- If you want a placeholder, use test.todo('does a thing') instead of it('does a thing').
- Otherwise, add the callback: it('does a thing', () => { ... }).
- Delete the line if it is leftover scaffolding.
Example fix
// before
it('calculates tax');
// after — intended placeholder
it.todo('calculates tax');
// or implemented
it('calculates tax', () => { expect(calc(10)).toBe(1); }); Defensive patterns
Strategy: validation
Validate before calling
function assertItHasBody(fn: unknown) {
if (fn === undefined) throw new Error('it needs a callback; use it.todo for placeholders');
} Type guard
function isItCall(args: [unknown, unknown]): boolean { return args.length >= 2; } Prevention
- Use it.todo('title') for placeholders rather than it('title').
- Lint for it/test calls missing a callback.
When it happens
Trigger: Calling `it('does a thing')` with no callback, or `it('does a thing', undefined)`. The check at Env.ts:554 (`fn === undefined`) throws at line 555.
Common situations: Writing a test title as a TODO before implementing the body; refactor that deleted the function but left the title; copy-paste missing the arrow function.
Related errors
- Invalid second argument, ${fn}. It must be a callback functi
- Todo must be called with only a description.
- Tests cannot be nested. Test "${spec.description}" cannot ru
- Missing second argument. It must be a callback function.
- Invalid second argument, ${specDefinitions}. It must be a ca
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/9018ad59203c5793.json.
Report an issue: GitHub.