This documentation covers Vitest v1 (old version). For the latest version, see https://vitest.dev.

Skip to content

Test Filtering

Filtering, timeouts, concurrent for suite and tests

CLI

You can use CLI to filter test files by name:

bash
$ vitest basic

Will only execute test files that contain basic, e.g.

basic.test.ts
basic-foo.test.ts
basic/foo.test.ts

You can also use the -t, --testNamePattern <pattern> option to filter tests by full name. This can be helpful when you want to filter by the name defined within a file rather than the filename itself.

Specifying a Timeout

You can optionally pass a timeout in milliseconds as third argument to tests. The default is 5 seconds.

ts
import {  } from 'vitest'

('name', async () => { /* ... */ }, 1000)

Hooks also can receive a timeout, with the same 5 seconds default.

ts
import {  } from 'vitest'

(async () => { /* ... */ }, 1000)

Skipping Suites and Tests

Use .skip to avoid running certain suites or tests

ts
import { , ,  } from 'vitest'

.('skipped suite', () => {
  ('test', () => {
    // Suite skipped, no error
    .(.(4), 3)
  })
})

('suite', () => {
  .('skipped test', () => {
    // Test skipped, no error
    .(.(4), 3)
  })
})

Selecting Suites and Tests to Run

Use .only to only run certain suites or tests

ts
import { , ,  } from 'vitest'

// Only this suite (and others marked with only) are run
.('suite', () => {
  ('test', () => {
    .(.(4), 3)
  })
})

('another suite', () => {
  ('skipped test', () => {
    // Test skipped, as tests are running in Only mode
    .(.(4), 3)
  })

  .('test', () => {
    // Only this test (and others marked with only) are run
    .(.(4), 2)
  })
})

Unimplemented Suites and Tests

Use .todo to stub suites and tests that should be implemented

ts
import { ,  } from 'vitest'

// An entry will be shown in the report for this suite
.('unimplemented suite')

// An entry will be shown in the report for this test
('suite', () => {
  .('unimplemented test')
})

Released under the MIT License.