vitest-dev/vitest · error · TypeError

Cannot use two functions as arguments. Please use the…

Error message

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

What it means

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.

Solutions

  1. Provide a single function: `test('x', () => { beforeFn(); return testFn() })`.
  2. If you need setup+body, use beforeEach plus a normal test, or aroundEach.
  3. Move the second function into options only if it is not a callback (it is not).

Example fix

// before
test('x', setup, runTest) // throws

// after
test('x', () => {
  setup()
  runTest()
})
Defensive patterns

Strategy: validation

Validate before calling

function assertSingleFunction(optsOrFn, optsOrTest) {
  if (typeof optsOrFn === 'function' && typeof optsOrTest === 'function') {
    throw new TypeError('test() accepts at most one function')
  }
}

Prevention

When it happens

Trigger: Writing `test('x', beforeFn, testFn)`; passing a setup function and a test function as separate args; refactoring that leaves two callbacks in sequence.

Common situations: Misreading the signature; merging a beforeEach helper into the test call by mistake; old snippets targeting a different framework.

Related errors


AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11). Data as JSON: /api/errors/11ece07b4f6f31e0. Report an issue: GitHub.

Appendix: source

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

  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 1fa9837ec2)