Vitest review: is it better than Jest?
Vitest comes with a UI that runs in the browser. It can show code, and even print out
console.log() calls! This might seem excessive for those who prefer the command line, but it makes for a lot of convenient things like drilling down to specific tests.
Vitest supports modern features like ES modules, TypeScript, JSX, PostCSS, async-await and more—all without the need for complex configuration. (docs)
Vitest makes migrating from Jest as easy as possible. It supports Jest assertions by default. That was exciting enough, but I was surprised to see that the Jest interop goes even further. Special functions like
jest.useFakeTimers() have equivalents Vitest as
Vitest also supports browser emulation via Jsdom… and there’s more.
Unlike Jest which always runs with Jsdom by default, Jsdom can be turned off in Vitest. In fact, there are options of what environment to emulate. As of v0.8, Vitest supports
Unlike Jest which automatically drops things into the global context (eg,
describe(), etc), Vitest requires importing them in every test file. While this may be a bit more typing, I think it’s more explicit and follows principle of least surprise.
It’s also possible to have them globalised automatically to make migration from Jest easier. (docs)
Vitest can run tests in parallel—and the feature is stable!
While Jest has
test.concurrent, it’s been considered as “experimental” for as long as Jest has been around. Vitest’s counterpart of
test.concurrent seems to be considered stable. Vitest has multi-threaded support built in and is enabled by default. (docs)