Skip to content
BENIBIX Learn

Vitest

Development🧪 Testing & QualityTest Frameworks

Also known as Vitest JS

A fast JavaScript test tool built on Vite, with an API much like Jest.

Think of it like

Think of it like a new bike. It is faster, but it rides just like your old one.

Example

Jack's Vite app moves from Jest to Vitest. His tests barely change, and the watch mode reruns a changed test in under a second.

Why it matters

Apps built with Vite get tests that share their settings, with no second set-up to keep in step.

Definition

Vitest is a fast test tool for JavaScript and TypeScript, built on the Vite build tool. Its test, expect and mock functions look almost the same as Jest's. So many projects can switch with few changes. It reuses the project's Vite settings, so tests understand the same files the app does. In watch mode it reruns only the tests touched by a change.

Example code

console
$ npx vitest run
      Tests  1 passed (1)
Vitest ran the test file once and reported one pass.

Common mistake

Running plain vitest in a build script. It waits for changes forever; use vitest run to run once.

Key takeaways

  1. 1
    Built on Vite. Shares its settings.
  2. 2
    Jest-like. Easy to switch.
  3. 3
    Fast reruns. Only what changed.

Compare