{"record":{"id":"9018ad59203c5793","repo":"jestjs/jest","slug":"missing-second-argument-it-must-be-a-callback-fun-9018ad","errorCode":null,"errorMessage":"Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.","messagePattern":"Missing second argument\\. It must be a callback function\\. Perhaps you want to use `test\\.todo` for a test placeholder\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-jasmine2/src/jasmine/Env.ts","lineNumber":563,"sourceCode":"        return spec;\n\n        function specResultCallback(result: SpecResult) {\n          clearResourcesForRunnable(spec.id);\n          currentSpec = null;\n          reporter.specDone(result);\n        }\n\n        function specStarted(spec: Spec) {\n          currentSpec = spec;\n          defaultResourcesForRunnable(spec.id, suite.id);\n          reporter.specStarted(spec.result);\n        }\n      };\n\n      this.it = function (description, fn, timeout) {\n        description = convertDescriptorToString(description);\n        if (fn === undefined) {\n          throw new Error(\n            'Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.',\n          );\n        }\n        if (typeof fn !== 'function') {\n          throw new TypeError(\n            `Invalid second argument, ${fn}. It must be a callback function.`,\n          );\n        }\n        const spec = specFactory(\n          description,\n          fn,\n          currentDeclarationSuite,\n          timeout,\n        );\n        if (currentDeclarationSuite.markedPending) {\n          spec.pend();\n        }\n","sourceCodeStart":545,"sourceCodeEnd":581,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-jasmine2/src/jasmine/Env.ts#L545-L581","documentation":"The `it()`/`test()` function requires a callback as its second argument. If `fn` is undefined (only the description was passed, or the second arg was explicitly omitted), Env.it throws this Error at Env.ts:563. The message specifically suggests `test.todo` because a common intent behind a no-callback test is a placeholder.","triggerScenarios":"Calling `it('does a thing')` with no callback, or `test('pending')`. The guard at Env.ts:562 checks `fn === undefined`.","commonSituations":"Writing a test stub/intention and forgetting the body; intending a todo but using `it` instead of `it.todo`/`test.todo`; a refactor that removed the callback but left the title.","solutions":["Add the callback: `it('does a thing', () => { expect(...).toBe(...) })`.","If you want a placeholder, use `test.todo('does a thing')` instead of `it(...)` with no body.","If you want to skip temporarily, use `it.skip('...', () => {})`."],"exampleFix":"// before\nit('will test the API');\n// after — either add a body or use todo\nit('will test the API', () => { /* ... */ });\n// or\ntest.todo('will test the API');","handlingStrategy":"type-guard","validationCode":"// Normalize: if no callback, convert to test.todo.\nfunction safeIt(name: string, fn?: () => void | Promise<void>, timeout?: number) {\n  if (fn === undefined) return it.todo(name);\n  return it(name, fn, timeout);\n}","typeGuard":"function hasCallback(fn: unknown): fn is () => void | Promise<void> {\n  return typeof fn === 'function';\n}","tryCatchPattern":null,"preventionTips":["Use `test.todo(name)` intentionally for placeholders rather than `it(name)`.","Enable eslint-plugin-jest rule 'require-top-level-describe' and 'no-test-callback'.","Always include a callback when writing an actual test."],"tags":["it","test","api-misuse","jasmine","todo","validation"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}