1001Ferramentas
Generators

Vitest test skeleton

Generate Vitest test skeleton (TS) with describe/it/expect.


  

Vitest: the modern, Vite-native testing framework

Vitest is a JavaScript testing framework created in 2021 by Anthony Fu and the Vite community, designed from the ground up to share Vite's transformation pipeline (esbuild / SWC) and its HMR-style watch mode. The result is a runner that feels familiar to anyone who has used Jest but is dramatically faster on modern stacks: there is no second transpiler, no separate dev/test toolchain, and the same vite.config.ts drives both the application and the tests. Vitest has become the default choice for Vue, Svelte, SolidJS and any project bootstrapped with Vite — and it works fine in React, Astro and even Node-only libraries.

A Vitest skeleton looks almost identical to a Jest one: describe, it / test and expect behave the same way, so migrating an existing suite is usually a search-and-replace exercise. The two main differences are the explicit import — import { describe, it, expect } from 'vitest' (Jest exposes them as globals by default) — and the runner command, which is vitest instead of jest.

Jest-compatible API with a few smart upgrades

Almost every Jest matcher works in Vitest: .toBe, .toEqual, .toMatchObject, .toThrow, .toMatchSnapshot, and so on. Mocks live under the vi namespace instead of jest:

  • vi.fn() — mock function with the same call-tracking API.
  • vi.spyOn(obj, 'method') — wrap an existing method.
  • vi.mock('module', factory) — replace an entire module; vi.hoisted() safely hoists shared values used inside that factory.
  • vi.useFakeTimers() / vi.advanceTimersByTime(ms) — control time deterministically.

In-source testing, snapshots and coverage

A unique Vitest feature is in-source testing: you can colocate tests inside the implementation file behind if (import.meta.vitest) { ... }, and the bundler strips them from the production build. This is great for tiny utility libraries where keeping spec and code side by side improves clarity. Snapshot testing matches Jest's behavior (.toMatchSnapshot, .toMatchInlineSnapshot). Coverage is collected via the V8 provider out of the box — fast and built into Node — or you can opt into the Istanbul provider if you need its detailed reports.

Browser mode, UI dashboard and workspaces

Vitest ships extras that Jest never had: a browser mode (still maturing) that runs component tests inside a real browser using Playwright or WebdriverIO; a UI dashboard via vitest --ui with a web interface for runs, filters and call traces; a workspace mode for monorepos where each package can have its own config; and a --typecheck flag that runs tsc --noEmit on test files alongside the test execution. Performance is the main selling point: on Vite-based projects benchmarks routinely show Vitest running 5-10x faster than Jest because there is no extra transformation step.

Framework integration

Through Vite plugins, Vitest works with virtually every modern framework: @vitejs/plugin-react for React, @vitejs/plugin-vue for Vue, @sveltejs/vite-plugin-svelte for Svelte. The entire @testing-library/* ecosystem works out of the box, so existing component tests for React or Vue continue to function with minimal changes.

FAQ

How hard is it to migrate from Jest? Usually a few mechanical changes: replace jest.* with vi.*, add explicit imports, adapt the config file to vite.config.ts with a test field, and review module-mocking calls. There are even automated codemods for large codebases.

Does it support React? Yes — install @vitejs/plugin-react and @testing-library/react, and set test.environment: 'jsdom' for DOM-aware tests.

Is Vitest always better than Jest? For Vite-based projects, almost always yes — same transform, much faster. For Webpack legacy projects without intent to migrate to Vite, Jest is still a perfectly reasonable choice.

Can it run in a real browser? Yes via browser mode, but the feature is still evolving — for stable end-to-end browser tests, pair Vitest (unit/component) with Playwright (E2E).

Does this generator send my code anywhere? No — the skeleton is built entirely in your browser. Nothing is uploaded to the server.

Related Tools