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

  1. Add the missing callback: `describe('my suite', () => { ... })`.
  2. If the suite body is not yet written, use an empty arrow function as a placeholder.
  3. 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

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


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)