explaingit

kulshekhar/ts-jest

7,077TypeScriptAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A Jest plugin that compiles TypeScript files on the fly as tests run and performs real type-checking, so type errors in your code can fail tests, not just IDE warnings.

Mindmap

mindmap
  root((ts-jest))
    What it does
      TypeScript in Jest
      Type checking tests
      On-the-fly compile
    Tech Stack
      TypeScript
      Jest
      Node.js
    Features
      Respects tsconfig
      Type error failures
      Single setup command
    Use Cases
      TS unit tests
      Type-safe mocking
      CI test pipelines
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Run Jest tests directly against TypeScript source files without a separate compile step.

USE CASE 2

Catch TypeScript type errors during test runs, adding an extra safety check beyond what your IDE provides.

USE CASE 3

Set up a TypeScript Jest testing environment in a new project with a single config-generation command.

Tech stack

TypeScriptJestNode.js

Getting it running

Difficulty · easy Time to first run · 30min

Jest and TypeScript must be installed first, ts-jest version must match Jest's major version number.

Free to use for any purpose, including commercial, with no restrictions other than keeping the copyright notice.

In plain English

Jest is a popular tool for running automated tests in JavaScript projects. It works by executing your test files and checking that the code behaves the way you expect. TypeScript is a variant of JavaScript that adds type annotations, which help catch certain kinds of bugs before the code runs, but it needs to be translated into plain JavaScript before it can run in most environments. The problem ts-jest solves is that Jest does not understand TypeScript files out of the box. Without a bridge, you either have to pre-compile your TypeScript to JavaScript before running tests, or use a tool like Babel that strips the type information away without actually checking it. ts-jest is a plugin for Jest, called a transformer, that handles TypeScript files on the fly as Jest runs. It compiles each file, respects the TypeScript configuration of your project, and importantly, performs actual type-checking rather than just stripping the types. This means a type error in your code can cause a test to fail, giving you an extra layer of safety. Setting it up requires installing Jest and TypeScript first, then adding ts-jest alongside a type definitions package, and running a single command to generate the configuration file. After that, running your tests works the same way as any other Jest project. The version numbering for ts-jest follows Jest's own major version number rather than the standard semantic versioning convention. The project notes that version 23.10 is a significant rewrite, so projects on an older workflow may need to pin to an earlier version to avoid breaking changes. ts-jest is open source under the MIT license and is supported by JetBrains, which provides a free open-source license for the project's development tools.

Copy-paste prompts

Prompt 1
Set up ts-jest in my TypeScript Node.js project and show me a working jest.config.ts and a sample test file.
Prompt 2
How do I configure ts-jest to skip type-checking for faster test runs while still supporting TypeScript syntax?
Prompt 3
I am getting a TypeScript error in ts-jest that does not appear in my IDE, how do I find out which tsconfig file ts-jest is using?
Prompt 4
How do I mock a TypeScript module in a ts-jest test so the mock is still correctly typed?
Prompt 5
I am upgrading from ts-jest 27 to ts-jest 29, what breaking changes should I watch out for?
Open on GitHub → Explain another repo

← kulshekhar on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.