vitest-dev/vitest · error · TypeError

Cannot use two functions as arguments. Please use the second

Error message

Cannot use two functions as arguments. Please use the second argument for options.

What it means

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).

Source

Thrown at packages/vitest/src/runtime/runner/suite.ts:288

  if (timeoutOrTest != null && typeof timeoutOrTest === 'object') {
    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.`)
  }

  let options: TestOptions = {}
  let fn: T | undefined

  // it('', () => {}, 1000)
  if (typeof timeoutOrTest === 'number') {
    options = { timeout: timeoutOrTest }
  }
  // it('', { retry: 2 }, () => {})
  else if (typeof optionsOrFn === 'object') {
    options = optionsOrFn
  }

  if (typeof optionsOrFn === 'function') {
    if (typeof timeoutOrTest === 'function') {
      throw new TypeError(
        'Cannot use two functions as arguments. Please use the second argument for options.',
      )
    }
    fn = optionsOrFn as T
  }
  else if (typeof timeoutOrTest === 'function') {
    fn = timeoutOrTest as T
  }

  return {
    options,
    handler: fn,
  }
}

// implementations
function createSuiteCollector(
  name: string,

View on GitHub (pinned to d568f8ce37)

Solutions

  1. Pass exactly one function as the test body, in either the second or third slot (not both).
  2. Use the second argument for options and the third for the function: `test('name', { retry: 2 }, () => {})`.
  3. Remove the duplicate function argument.

Example fix

// before
test('name', () => { setup() }, () => { expect(x).toBe(1) })
// after
test('name', () => {
  setup()
  expect(x).toBe(1)
})
Defensive patterns

Strategy: validation

Validate before calling

function hasTwoFunctionArgs(a: unknown, b: unknown): boolean {
  return typeof a === 'function' && typeof b === 'function'
}
if (hasTwoFunctionArgs(optionsOrFn, timeoutOrTest)) {
  throw new Error('Pass only one function to test()')
}

Prevention

When it happens

Trigger: 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.

Common situations: Misunderstanding the argument order; refactoring that duplicates the function argument; editor auto-complete inserting an extra arrow function.

Related errors


AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03). Data as JSON: /data/errors/11ece07b4f6f31e0.json. Report an issue: GitHub.