jestjs/jest · error · TypeError
Invalid second argument
Error message
Invalid second argument, ${specDefinitions}. It must be a callback function. What it means
describe's second argument must be a function. If a non-undefined, non-function value is passed (a string, object, number, array), Env.describe throws a TypeError naming the offending value. This is a stricter check than the undefined guard and catches wrong-typed arguments.
Solutions
- Ensure the second argument is a function: `describe('x', () => {})`.
- If you intended a factory/helper, call it so it returns a function, or wrap: `describe('x', () => myHelper())`.
- Double-check the value of any variable passed — log it before the describe call.
Example fix
// before
describe('my suite', { timeout: 5000 });
// after
describe('my suite', () => {
beforeEach(() => {}, 5000);
}); Defensive patterns
Strategy: type-guard
Validate before calling
function safeDescribe(name: string, fn: unknown) {
if (typeof fn !== 'function') {
throw new TypeError(`describe('${name}') second argument must be a function, got ${typeof fn}`);
}
return describe(name, fn as () => void);
} Type guard
function isFunction(value: unknown): value is Function {
return typeof value === 'function';
} Prevention
- Ensure the describe callback is a function literal or a verified function reference.
- Avoid passing config objects or strings as the describe callback.
- Use TypeScript with strict callback types for test helpers.
When it happens
Trigger: Calling `describe('x', 'not a function')` or `describe('x', { foo: 1 })` or passing a config object where the callback was expected. The guard at Env.ts:405 checks `typeof specDefinitions !== 'function'`.
Common situations: Calling describe with an options object instead of a callback; passing the result of an assignment expression that returned a non-function; a helper that returns the wrong type; copy-paste from a table-driven test where the table was passed as the second arg.
Related errors
- describe does not expect any arguments
- Invalid first argument. It must be a callback function.
- Invalid second argument
- Missing second argument. It must be a callback function.
- Argument passed to callFake should be a function, got
AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10).
Data as JSON: /api/errors/3644f41f6ffd5f4e.
Report an issue: GitHub.
Appendix: source
Thrown at packages/jest-jasmine2/src/jasmine/Env.ts:406
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 8e6d128e4a)