{"record":{"id":"11ece07b4f6f31e0","repo":"vitest-dev/vitest","slug":"cannot-use-two-functions-as-arguments-please-use","errorCode":null,"errorMessage":"Cannot use two functions as arguments. Please use the second argument for options.","messagePattern":"Cannot use two functions as arguments\\. Please use the second argument for options\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/runner/suite.ts","lineNumber":284,"sourceCode":"  if (timeoutOrTest != null && typeof timeoutOrTest === 'object') {\n    throw new TypeError(`Signature \"test(name, fn, { ... })\" was deprecated in Vitest 3 and removed in Vitest 4. Please, provide options as a second argument instead.`)\n  }\n\n  let options: TestOptions = {}\n  let fn: T | undefined\n\n  // it('', () => {}, 1000)\n  if (typeof timeoutOrTest === 'number') {\n    options = { timeout: timeoutOrTest }\n  }\n  // it('', { retry: 2 }, () => {})\n  else if (typeof optionsOrFn === 'object') {\n    options = optionsOrFn\n  }\n\n  if (typeof optionsOrFn === 'function') {\n    if (typeof timeoutOrTest === 'function') {\n      throw new TypeError(\n        'Cannot use two functions as arguments. Please use the second argument for options.',\n      )\n    }\n    fn = optionsOrFn as T\n  }\n  else if (typeof timeoutOrTest === 'function') {\n    fn = timeoutOrTest as T\n  }\n\n  return {\n    options,\n    handler: fn,\n  }\n}\n\n// implementations\nfunction createSuiteCollector(\n  name: string,","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/runtime/runner/suite.ts#L266-L302","documentation":"TypeError thrown by parseArguments when both the second and third arguments to test()/it() are functions. The API allows at most one function (the test body); the other non-name slot must be options (object) or timeout (number). Two functions is ambiguous and usually indicates a misplaced callback.","triggerScenarios":"Writing `test('x', beforeFn, testFn)`; passing a setup function and a test function as separate args; refactoring that leaves two callbacks in sequence.","commonSituations":"Misreading the signature; merging a beforeEach helper into the test call by mistake; old snippets targeting a different framework.","solutions":["Provide a single function: `test('x', () => { beforeFn(); return testFn() })`.","If you need setup+body, use beforeEach plus a normal test, or aroundEach.","Move the second function into options only if it is not a callback (it is not)."],"exampleFix":"// before\ntest('x', setup, runTest) // throws\n\n// after\ntest('x', () => {\n  setup()\n  runTest()\n})","handlingStrategy":"validation","validationCode":"function assertSingleFunction(optsOrFn, optsOrTest) {\n  if (typeof optsOrFn === 'function' && typeof optsOrTest === 'function') {\n    throw new TypeError('test() accepts at most one function')\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass exactly one function to test().","Merge setup into the body rather than passing two callbacks.","Use beforeEach/aroundEach for setup that must precede the test."],"tags":["api-signature","validation"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}