ts-jest

29.4.9 · active · verified Sat Apr 18

ts-jest is a Jest transformer with source map support that enables testing projects written in TypeScript using Jest. It supports all TypeScript features, including type-checking. The current stable version is 29.4.9. Note that ts-jest does not follow semantic versioning, which means major breaking changes can occur without a corresponding major version increment. Releases are frequent, primarily for patch updates.

Common errors

Warnings

Install

Quickstart

This quickstart shows how to set up `ts-jest` for a basic TypeScript project. It includes the necessary `package.json` dependencies and `scripts`, a minimal `jest.config.ts` (generated via `npx ts-jest config:init`), a simple TypeScript function, and its corresponding test file. After installation and configuration, tests can be run using `npm test`.

{
  "devDependencies": {
    "jest": "^29.4.9",
    "typescript": "^5.0.0",
    "ts-jest": "^29.4.9",
    "@types/jest": "^29.4.9"
  },
  "scripts": {
    "test": "jest"
  }
}

// jest.config.ts (created by `npx ts-jest config:init`)
export default {
  preset: 'ts-jest',
  testEnvironment: 'node',
  roots: ['<rootDir>/src'],
};

// src/sum.ts
export function sum(a: number, b: number): number {
  return a + b;
}

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

describe('sum', () => {
  it('adds two numbers', () => {
    expect(sum(1, 2)).toBe(3);
  });
});

view raw JSON →