TypeScript Academy · Lesson

Vitest/Jest setup for TS

Install and configure Vitest or Jest for TypeScript projects; write a tiny test and run it.

Lesson 1 of 38 steps

Vitest/Jest setup for TS is a free TypeScript Academy lesson on CoddyKit. This is lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, and your progress syncs across the web and the CoddyKit app. The TypeScript Academy course includes 3 lessons in total.

Intro

Goal: Configure Vitest or Jest for TypeScript. You'll install deps, add a config, write one tiny test, and run it.

Install Vitest

Vitest is Vite-native: fast startup, ESM-first, great DX. Install alongside @types/node for globals.

npm install --save-dev vitest @vitest/ui @types/node

Vitest example

Add vitest.config.ts, write a tiny test, and run with npx vitest or npm test script.

// vitest.config.ts
import { defineConfig } from "vitest/config";
export default defineConfig({
  test: { globals: true }
});

// src/sum.ts
export const sum = (a: number, b: number) => a + b;

// src/sum.test.ts
import { sum } from "./sum";
import { describe, expect, it } from "vitest";

describe("sum", () => {
  it("adds numbers", () => {
    expect(sum(2, 3)).toBe(5);
  });
});

Install Jest

Jest needs a transformer for TS. Use ts-jest to compile tests on the fly.

npm install --save-dev jest ts-jest @types/jest @types/node

Jest example

Set preset: "ts-jest". Jest will run .ts tests without a build step.

// jest.config.js
module.exports = {
  preset: "ts-jest",
  testEnvironment: "node",
};

// src/sum.test.ts
import { sum } from "./sum";

test("adds numbers", () => {
  expect(sum(2, 3)).toBe(5);
});

Scripts

Add scripts for a smooth workflow. Use watch mode for fast feedback during development.

// package.json (scripts)
{
  "scripts": {
    "test": "vitest",
    "test:ui": "vitest --ui",
    "test:jest": "jest"
  }
}

Question

Quick check: In a Jest + TS setup, what does ts-jest do?

Recap

Recap: Vitest (Vite-native) and Jest (widely used) both work great with TS. Configure once, then run tests in watch/CI.

Free to start

Learn TypeScript with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
101
Lessons
352

Frequently Asked Questions

Is the “Vitest/Jest setup for TS” lesson free?

Yes — the full text of “Vitest/Jest setup for TS” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO. The TypeScript Academy course includes 3 lessons in total.

What will I learn in “Vitest/Jest setup for TS”?

Install and configure Vitest or Jest for TypeScript projects; write a tiny test and run it. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start TypeScript Academy?

No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 3.

How long does the “Vitest/Jest setup for TS” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this TypeScript Academy lesson?

Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Vitest/Jest setup for TS
  2. Typing tests & mocks; expectTypeOf
  3. E2E typing glimpses (Playwright/Cypress)
← Back to TypeScript Academy