Skip to content
Vitest 3
Main Navigation Guide & APIConfigBrowser ModeAdvanced API
3.2.0
2.1.9
1.6.1
0.34.6

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

Appearance

Sidebar Navigation

Introduction

Why Vitest

Getting Started

Features

Config Reference

API

Test API Reference

Mock Functions

Vi Utility

Expect

ExpectTypeOf

Assert

AssertType

Guides

CLI

Test Filtering

Test Projects

Reporters

Coverage

Snapshot

Mocking

Parallelism

Testing Types

Vitest UI

In-Source Testing

Test Context

Test Annotations

Environment

Extending Matchers

IDE Integration

Debugging

Common Errors

Migration Guide

Migrating to Vitest 3.0

Migrating from Jest

Performance

Profiling Test Performance

Improving Performance

Browser Mode

Node API Reference

Comparisons

On this page

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.

Since Vitest 3, you can also specify the test by filename and line number:

bash
$ vitest basic/foo.test.ts:10

WARNING

Note that Vitest requires the full filename for this feature to work. It can be relative to the current working directory or an absolute file path.

bash
$ vitest basic/foo.js:10 # ✅
$ vitest ./basic/foo.js:10 # ✅
$ vitest /users/project/basic/foo.js:10 # ✅
$ vitest foo:10 # ❌
$ vitest ./basic/foo:10 # ❌

At the moment Vitest also doesn't support ranges:

bash
$ vitest basic/foo.test.ts:10, basic/foo.test.ts:25 # ✅
$ vitest basic/foo.test.ts:10-25 # ❌

Specifying a Timeout ​

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

ts
import { test } from 'vitest';

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

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

ts
import { beforeAll } from 'vitest';

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

Skipping Suites and Tests ​

Use .skip to avoid running certain suites or tests

ts
import { assert, describe, it } from 'vitest';

describe.skip('skipped suite', () => {
  it('test', () => {
    // Suite skipped, no error
    assert.equal(Math.sqrt(4), 3);
  });
});

describe('suite', () => {
  it.skip('skipped test', () => {
    // Test skipped, no error
    assert.equal(Math.sqrt(4), 3);
  });
});

Selecting Suites and Tests to Run ​

Use .only to only run certain suites or tests

ts
import { assert, describe, it } from 'vitest';

// Only this suite (and others marked with only) are run
describe.only('suite', () => {
  it('test', () => {
    assert.equal(Math.sqrt(4), 3);
  });
});

describe('another suite', () => {
  it('skipped test', () => {
    // Test skipped, as tests are running in Only mode
    assert.equal(Math.sqrt(4), 3);
  });

  it.only('test', () => {
    // Only this test (and others marked with only) are run
    assert.equal(Math.sqrt(4), 2);
  });
});

Unimplemented Suites and Tests ​

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

ts
import { describe, it } from 'vitest';

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

// An entry will be shown in the report for this test
describe('suite', () => {
  it.todo('unimplemented test');
});
Pager
Previous pageCLI
Next pageTest Projects

Released under the MIT License.

Copyright (c) 2021-Present Vitest Team

https://vitest.dev/guide/filtering

Released under the MIT License.

Copyright (c) 2021-Present Vitest Team