{"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":288,"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":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/runtime/runner/suite.ts#L270-L306","documentation":"In `parseArguments` (suite.ts:286-291), if both the second argument (`optionsOrFn`) and the third argument (`timeoutOrTest`) are functions, a `TypeError` is thrown. The API supports at most one function (the test body); passing two is ambiguous and almost always a mistake (e.g. two callbacks).","triggerScenarios":"Calling `test('name', () => {}, () => {})` — two functions; accidentally passing a callback factory as the second arg and the actual test fn as the third; copy-paste errors.","commonSituations":"Misunderstanding the argument order; refactoring that duplicates the function argument; editor auto-complete inserting an extra arrow function.","solutions":["Pass exactly one function as the test body, in either the second or third slot (not both).","Use the second argument for options and the third for the function: `test('name', { retry: 2 }, () => {})`.","Remove the duplicate function argument."],"exampleFix":"// before\ntest('name', () => { setup() }, () => { expect(x).toBe(1) })\n// after\ntest('name', () => {\n  setup()\n  expect(x).toBe(1)\n})","handlingStrategy":"validation","validationCode":"function hasTwoFunctionArgs(a: unknown, b: unknown): boolean {\n  return typeof a === 'function' && typeof b === 'function'\n}\nif (hasTwoFunctionArgs(optionsOrFn, timeoutOrTest)) {\n  throw new Error('Pass only one function to test()')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass exactly one function as the test body.","Use options object + single function, never two functions.","Review copy-pasted test scaffolding for duplicated arrows."],"tags":["signature","validation","test-definition","argument-error"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}