vitest-dev/vitest · error · TypeError

Signature "test(name, fn, )" was deprecated in Vitest 3 and…

Error message

Signature "test(name, fn, { ... })" was deprecated in Vitest 3 and removed in Vitest 4. Please, provide options as a second argument instead.

What it means

TypeError thrown by parseArguments when the third positional argument to test()/it() is an object. Vitest 3 deprecated the `test(name, fn, { options })` signature and Vitest 4 removed it; options must now be the second argument: `test(name, { options }, fn)`. The check keys off `typeof timeoutOrTest === 'object'`.

Solutions

  1. Reorder to the new signature: `test('x', { retry: 2 }, () => {})`.
  2. Use a codemod or grep for `test(.*,.*,.*{` to find all occurrences and rewrite.
  3. If you need only a timeout, the numeric third arg is still allowed: `test('x', fn, 1000)`.

Example fix

// before (removed in v4)
test('x', () => {}, { retry: 2, timeout: 5000 })

// after
test('x', { retry: 2, timeout: 5000 }, () => {})
Defensive patterns

Strategy: validation

Validate before calling

// Before test(), check argument shape:
function safeTest(name, optsOrFn, optsOrTest) {
  if (typeof optsOrFn === 'function' && optsOrTest && typeof optsOrTest === 'object') {
    throw new TypeError('Use test(name, options, fn) in Vitest 4')
  }
  return test(name, optsOrFn, optsOrTest)
}

Prevention

When it happens

Trigger: Writing `test('x', () => {}, { retry: 2 })`; using a shared config object as the third argument; copy-pasting Vitest 2/3 examples that predate the signature change.

Common situations: Upgrading a codebase from Vitest 1/2/3 to Vitest 4; using outdated documentation or AI-generated snippets with the old signature.

Related errors


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

Appendix: source

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

export function createSuiteHooks(): SuiteHooks {
  return {
    beforeAll: [],
    afterAll: [],
    beforeEach: [],
    afterEach: [],
    aroundEach: [],
    aroundAll: [],
  }
}

const POSITIVE_INFINITY = Number.POSITIVE_INFINITY

function parseArguments<T extends (...args: any[]) => any>(
  optionsOrFn: T | object | undefined,
  timeoutOrTest: T | number | undefined,
) {
  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.',

View on GitHub (pinned to 1fa9837ec2)