Registry / testing / ts-jest

ts-jest

JSON →
library29.4.9jsnpmunverified

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.

npm install ts-jest
INSTALL
IMPORT
SIG · TS-JEST
T
ts-jest
testingjavascriptv29.4.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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); }); });
Debug
Known issues
breakingts-jest explicitly states it does not follow semantic versioning. This means breaking changes can occur in minor or even patch releases, making upgrades potentially risky.
fix
Always review the CHANGELOG.md before upgrading ts-jest, especially across minor versions, and thoroughly test your application after any update.
affects: >=23.10.0
gotchats-jest has strict peer dependency requirements for Jest and TypeScript versions. Incompatible versions can lead to unexpected errors or installation failures.
fix
Ensure that your installed versions of `jest` (`^29.0.0 || ^30.0.0`) and `typescript` (`>=4.3 <7`) match the peer dependency range specified by ts-jest.
affects: >=29.0.0
gotchaThere's a fundamental difference between using `ts-jest` for TypeScript compilation and using Babel with `@babel/preset-typescript`. `ts-jest` handles type-checking and Jest integration, while Babel with `preset-typescript` only strips types, potentially missing type errors.
fix
Choose the appropriate tool based on your project's needs. If you require full TypeScript type-checking during tests, `ts-jest` is the correct choice. If you only need fast transpilation without type checks, Babel might be preferred (though often used with other transformers).
affects: *
Errors
Common errors & fixes
Jest: ts-jest preset was not applied. Ensure that you have configured jest.config.js/ts to use a preset.
The Jest configuration file (`jest.config.js` or `jest.config.ts`) does not include `preset: 'ts-jest'`.
fix
Add `preset: 'ts-jest'` to your Jest configuration file, for example: `export default { preset: 'ts-jest' };`
Cannot find module 'typescript' or 'jest' or '@jest/types'
A required peer dependency of `ts-jest` (like `typescript`, `jest`, `@jest/types`, `babel-jest`, etc.) is not installed or its version is incompatible.
fix
Install all necessary peer dependencies explicitly using `npm install -D jest typescript @types/jest ts-jest` (or `yarn add --dev ...`) and ensure their versions fall within the ranges specified by `ts-jest`.
Error: Jest: a transformer must at least provide a `process` function.
This usually indicates an incompatibility between `ts-jest` and the installed version of Jest or TypeScript, or a corrupted `node_modules`.
fix
Verify that your `jest` and `typescript` versions satisfy `ts-jest`'s peer dependency requirements. Try clearing your `node_modules` and `npm cache clean --force` (or `yarn cache clean`), then reinstall dependencies.
TSxxxx: [TypeScript compilation error]
TypeScript compiler errors are being reported during the test run, indicating issues with your code's types or `tsconfig.json` configuration.
fix
Address the specific TypeScript errors in your source or test files. Ensure your `tsconfig.json` (especially `compilerOptions` like `target`, `module`, `strict`) is correctly configured for your project and `ts-jest`.
Upgrade
Version history
29.4.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
ts-jest — npm install ts-jest · libregistry