Vitest
A blazing fast unit test framework powered by Vite.
Get involved!
⚠️ DISCLAIMER: Vitest is still in development and not stable yet. It's not recommended to use it in production.
Vitest requires Vite v2.7 and Node v14
Follow the Getting Started Guide or learn why we are building a new test runner.
Documentation
Read the documentation.
Features
- Vite's config, transformers, resolvers, and plugins. Use the same setup from your app!
- Jest Snapshot
- Chai built-in for assertions, with Jest expect compatible APIs.
- Smart & instant watch mode, like HMR for tests!
- Native code coverage via c8
- Tinyspy built-in for mocking, stubbing, and spies.
- JSDOM and happy-dom for DOM and browser API mocking
- Components testing (Vue, React, Lit, Vitesse)
- Workers multi-threading via tinypool (a lightweight fork of Piscina)
- ESM first, top level await
- Out-of-box TypeScript / JSX support
- Filtering, timeouts, concurrent for suite and tests
import { it, describe, expect, assert } 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
Examples
- Unit Testing
- Vue Component Testing
- React Component Testing
- React Testing with MSW
- Lit Component Testing
- Vitesse Component Testing
Projects using Vitest
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!
License
MIT License © 2021-Present Anthony Fu, Matias Capeletto