---
title: "Use Jest for JavaScript unit tests · Agent Wranglers"
url: https://agentwranglers.se/playbook/stack/testing-and-code-quality/jest
updated: 2026-10-21
licence: "All rights reserved"
---

# Use Jest for JavaScript unit tests

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- Level: Recommended
- Chapter: [Testing and code quality](https://agentwranglers.se/playbook/stack/testing-and-code-quality)
- Rule: Run JavaScript and TypeScript unit tests with Jest, with one config file at the project root.
- Cost: Open source. MIT licence, free to use in any project.
- How: Jest has had stable releases since 2016, and 30.5.2 came out in September 2026. npm counted almost 26 million downloads in the week to 18 October 2026. It is MIT licensed and part of the OpenJS Foundation. AI tools have seen years of its `describe`, `test` and `expect` code. Choose something else when the app builds with Vite. Vitest reuses the Vite config and has more downloads, but its 1.0 shipped in December 2023. Record it as an exception, as [Pick software proven in production for five years](https://agentwranglers.se/playbook/stack/how-to-choose/proven-for-five-years) asks.
- Check: `npx jest --listTests` lists every test file, and `package.json` lists only one of `jest`, `vitest` and `mocha`.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
// 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

```json
{
  "scripts": { "test": "jest" },
  "jest": { "testEnvironment": "node", "randomize": true }
}
```

## Sources

- [Jest documentation](https://jestjs.io/docs/getting-started)

## Related rules

- [Pick software proven in production for five years](https://agentwranglers.se/playbook/stack/how-to-choose/proven-for-five-years) in Software choices
- [Use your test runner to run evals on a fixed example set](https://agentwranglers.se/playbook/stack/ai-software/evals-in-test-runner) in Software choices

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/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.

- Previous: [Use pytest for Python tests](https://agentwranglers.se/playbook/stack/testing-and-code-quality/pytest)
- Next: [Use Playwright for browser tests](https://agentwranglers.se/playbook/stack/testing-and-code-quality/playwright)
- [Testing and code quality](https://agentwranglers.se/playbook/stack/testing-and-code-quality)
