vitest README

The project's README from github.com/vitest-dev/vitest. As one markdown file: README.md.



Vitest logo


Vitest

Next generation testing framework powered by Vite.

current vitest version badge

Get involved!

Documentation | Getting Started | Examples | Why Vitest?

中文文档



Features

Vitest requires Vite >=v6.4.0 and Node >=v22.12.0

import { assert, describe, expect, it } from 'vitest'

describe('suite name', () => {
  it('foo', () => {
    expect(1 + 1).toEqual(2)
    expect(true).to.be.true
  })

  it('bar', () => {
    assert.equal(Math.sqrt(4), 2)
  })

  it('snapshot', () => {
    expect({ foo: 'bar' }).toMatchSnapshot()
  })
})
$ npx vitest

Sponsors

vitest's sponsors

Credits

Thanks to:

Contribution

See Contributing Guide.

License

MIT License © 2021-Present VoidZero Inc. and Vitest contributors

vitest (vitest-dev/vitest)

Searching Database…

17.3K ·GitHub
What is this?Vitest is a next-generation testing framework for JavaScript and TypeScript, powered by Vite. It runs unit and component tests using your existing Vite setup.
Is Vitest a framework or a library, and how does it relate to Jest?It is a full testing framework built on Vite: it reuses Vite's config, transformers, resolvers and plugins, and offers a Jest-compatible API (expect, mocking, spies, snapshots) so switching feels familiar.
How do I get it running in my project?Install it as a dev dependency (npm install -D vitest) and run the 'vitest' CLI. It is ESM-first and picks up your app's existing vite config and plugins, so most projects need no separate test config.
Do I need anything specific installed first?Yes — Node >=v22.12.0 (22.12, 24, or 26+) and Vite >=v6.4.0 in your project. Nothing else is mandatory; the browser is only involved if you opt into Browser Mode.
What should I watch out for if I am coming from Jest or an older setup?The main gotcha is the version floor: projects on older Node or Vite must upgrade first. Migration from Jest itself is easy since the expect API, mocking, stubbing, spies and snapshots are compatible.
What can it do besides run unit tests?It measures native code coverage via v8 or istanbul, runs benchmarks with Tinybench, does type-level testing with expect-type, and supports sharding to split a run across machines.
Can it test Vue, React or Svelte components?Yes — component testing for Vue, React, Svelte, Lit and Marko out of the box, plus a Browser Mode that runs tests natively in the browser. In Node it can mock DOM and browser APIs via JSDOM or happy-dom.
Why do people call it fast?Its watch mode works like Vite's HMR: smart and instant, rerunning only what is affected when you edit instead of the whole suite. Tests can also run concurrently and be filtered.
Do I have to configure TypeScript, JSX or ESM support?No — TypeScript and JSX work out of the box, and Vitest is ESM-first with top-level await supported natively.
Creator
vitest-dev
Size
72.4 MB
Stars
17.3K
Age
4y
Commits · 90 Days