STK-40Default Open source
Use Vitest with Vite and Jest elsewhere for JavaScript unit tests
Run JavaScript and TypeScript unit tests with Vitest when the app builds with Vite, which is the default build here. Use Jest for code that has no Vite build. Keep one config file at the project root.
Review by
2027-04-30
How to do it
Vitest is a recorded exception to the five-year test, dated 27 October 2026, because its 1.0 shipped on 4 December 2023. It reuses the Vite config, so tests see the same aliases and plugins as the app. Jest's own documentation says Jest is not supported by Vite. Version 5.0.5 shipped on 15 October 2026. npm counted about 68 million downloads in the week to 1 July 2026, the latest week its download API reported. It is MIT licensed, and its describe, test and expect follow Jest's, so agents write it well. Jest has had stable releases since 2016, and 30.5.2 came out in September 2026. It is MIT licensed and part of the OpenJS Foundation. Use it for a Node.js library or server with no Vite build, or where a large Jest suite already passes. The build pick is Use Vite to build and serve the front end.
Examples
JavaScript example
// prices.test.js
import { total } from './prices.js';
test('adds every line', () => {
expect(total([{ price: 120, qty: 2 }, { price: 30, qty: 1 }])).toBe(270);
});
JSON example
{
"scripts": { "test": "vitest run --sequence.shuffle" },
"devDependencies": { "vitest": "^5.0.5" }
}
How to check
npx jest --listTests, or npx vitest list with Vite, lists every test file, and package.json lists only one of jest, vitest and mocha.
Sources
Related rules
- STK-18 Use Vite to build and serve the front end in Software choices
- STK-90 Use your test runner to run evals on a fixed example set in Software choices
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/stack/testing-and-code-quality/jest">Agent Wranglers software choices playbook</a>. In code you write, add a comment next to it with the same link.