Vitest

A Vite-native test framework. It's fast!

README

Vitest

A blazing fast unit test framework powered by Vite.

Get involved!

Documentation | Getting Started | Examples | Why Vitest?

中文文档



Features


- Vite's config, transformers, resolvers, and plugins. Use the same setup from your app!
- Chai built-in for assertions, with Jest expect compatible APIs.
- Smart & instant watch mode, like HMR for tests!
- Native code coverage via c8 or [istanbul](https://istanbul.js.org/).
- Tinyspy built-in for mocking, stubbing, and spies.
- JSDOM and happy-dom for DOM and browser API mocking
- Components testing (Vue, React, Svelte, Lit, Vitesse)
- Workers multi-threading via Tinypool (a lightweight fork of Piscina)
- Benchmarking support with Tinybench
- ESM first, top level await
- Out-of-box TypeScript / JSX support
- Filtering, timeouts, concurrent for suite and tests

Vitest requires Vite >=v3.0.0 and Node >=v14



  1. ```ts
  2. import { assert, describe, expect, it } from 'vitest'

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

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

  11.   it('snapshot', () => {
  12.     expect({ foo: 'bar' }).toMatchSnapshot()
  13.   })
  14. })
  15. ```

  1. ``` sh
  2. $ npx vitest
  3. ```

Sponsors


Anthony Fu Sponsors



Patak Sponsors



Credits


Thanks to:

- The Jest team and community for creating a delightful testing API
- @lukeed for the work on uvu where we are inspired a lot from.
- @pi0 for the idea and implementation of using Vite to transform and bundle the server code.
- The Vite team for brainstorming the initial idea.
- @patak-dev for the awesome package name!

Contribution


License


MIT License © 2021-Present Anthony Fu, Matias Capeletto