If you use Angular CLI this library would be very helpful.
It will allow you to keep your workspace clear of boilerplate code related to Jest setup and also run your tests with Angular CLI (ng test).
This will also save you the trouble of configuring Jest.

As for your specific error, it is most probably related to your tsconfig.spec.json. Have you changed the module field to commonjs? This is required to make Jest work.

For more details read this article.

Disclaimer: I'm the owner of this library.

Answer from JeB on Stack Overflow
🌐
DEV Community
dev.to › fransaoco › how-to-set-up-jest-in-angular-19-step-by-step-guide-1c2p
How to Set Up Jest in Angular 19 (Step-by-Step Guide) - DEV Community
April 21, 2025 - module.exports = { preset: 'jest-preset-angular', setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'], testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/dist/'], transform: { '^.+\\.ts$': 'ts-jest', // Only transform .ts files }, transformIgnorePatterns: [ '/node_modules/(?!flat)/', // Exclude modules except 'flat' from transformation ], }; import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone'; setupZoneTestEnv(); { "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/spec", "types": ["jest", "node"] }, "include": [ "src/**/*.spec.ts", "src/**/*.d.ts" ] } "test": { "builder": "@angular-devkit/build-angular:jest", "options": { "tsConfig": "tsconfig.spec.json" } } "compilerOptions": { "baseUrl": "./", ...
🌐
Medium
medium.com › @philip.mutua › setting-up-jest-in-your-angular-16-project-3638ef65f3a3
Setting Up Jest in Your Angular Project | by Philip Mutua | Medium
December 10, 2024 - In your angular application locate the karma.config.js file your angular project has these two files delete them. ... To kickstart your enhanced testing experience, begin by installing the required dependencies using your preferred package manager · # Using Yarn yarn add -D jest jest-preset-angular @types/jest # Using npm npm install -D jest jest-preset-angular @types/jest
🌐
Tim Deschryver
timdeschryver.dev › blog › integrate-jest-into-an-angular-application-and-library
Integrate Jest into an Angular application and library
The jest-preset-angular library ... all the dependencies we need. ... Secondly, we create a setup-jest.ts file in the root and import jest-preset-angular inside of it....
🌐
GitHub
github.com › thymikee › jest-preset-angular
GitHub - thymikee/jest-preset-angular: Jest configuration preset for Angular projects. · GitHub
A preset of Jest configuration for Angular projects.
Starred by 916 users
Forked by 304 users
Languages   TypeScript 89.7% | JavaScript 7.1% | CSS 2.8%
🌐
Jest
jestjs.io › getting started
Getting Started · Jest
Jest will set process.env.NODE_ENV to 'test' if it's not set to something else. You can use that in your configuration to conditionally setup only the compilation needed for Jest, e.g.
🌐
Thymikee
thymikee.github.io › installation
Installation | jest-preset-angular
3 weeks ago - import type { Config } from 'jest'; import { createCjsPreset } from 'jest-preset-angular/presets/index.js'; export default { ...createCjsPreset(), setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'], } satisfies Config;
🌐
npm
npmjs.com › package › jest-preset-angular
jest-preset-angular - npm
3 weeks ago - A preset of Jest configuration for Angular projects.
      » npm install jest-preset-angular
    
Published   Apr 09, 2026
Version   16.1.4
Find elsewhere
🌐
Medium
medium.com › @zeeshankhan8838 › unit-testing-angular-with-jest-configuration-e324ec61620c
Jest Configuration in angular. In this article, I am writing about all… | by zeeshan khan | Medium
March 22, 2023 - "jest": { "preset": "jest-preset-angular", "setupFilesAfterEnv": [ "<rootDir>/src/setup.jest.ts" ], "testPathIgnorePatterns": [ "<rootDir>/node_modules/", "<rootDir>/dist/" ], "globals": { "ts-jest": { "tsConfig": "<rootDir>/tsconfig.spec.json", "stringifyContentPathRegex": "\\.html$" } } } "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "watch": "ng build --watch --configuration development", "test": "jest", "test:watch": "jest --watch", "test:coverage": "jest --coverage" },
🌐
Medium
medium.com › ngconf › configure-jest-in-angular-18-79765fdb0fae
Step-by-Step Jest Configuration for Angular 18 | ngconf
August 27, 2024 - Guide to set up Jest for Angular 18 applications for faster, smoother testing. Steps to uninstall Karma/Jasmine and configure Jest included
🌐
Beyondjava
beyondjava.net › angular-17-jest-mono-repo-manually
How to set up Jest for an Angular 17 monorepo manually
January 1, 2024 - Beyond Java · Sitemap · Talks & Articles · Projects · Guest Posts · About · Legalese · Statistics · (opt out) · Mastodon
🌐
DEV Community
dev.to › alfredoperez › angular-10-setting-up-jest-2m0l
Angular 11 - Setting up Jest - DEV Community
December 24, 2020 - "jest": { "preset": "jest-preset-angular", "setupFilesAfterEnv": [ "<rootDir>/setupJest.ts" ], "testPathIgnorePatterns": [ "<rootDir>/node_modules/", "<rootDir>/dist/" ], "globals": { "ts-jest": { "tsConfig": "<rootDir>/tsconfig.spec.json", "stringifyContentPathRegex": "\\.html$" } } }
🌐
Amadou Sall
amadousall.com › how-to-set-up-angular-unit-testing-with-jest
How to Set Up Angular Unit Testing with Jest - Amadou Sall
June 14, 2022 - The jest-preset-angular package is the tool that makes it possible to run our Angular unit tests using Jest.
🌐
npm
npmjs.com › package › @angular-builders › jest
angular-builders/jest
January 14, 2026 - ... $ npm remove karma karma-chrome-launcher karma-coverage-istanbul-reporter karma-jasmine karma-jasmine-html-reporter $ rm ./karma.conf.js ./src/test.ts · Install the builder (and jest if you still haven't): $ npm i -D jest @types/jest @angular...
      » npm install @angular-builders/jest
    
Published   Jan 14, 2026
Version   21.0.3
🌐
Angular Training
angulartraining.com › home › how to use jest for angular unit tests?
How to use Jest for Angular Unit Tests? | Angular Newsletter
September 13, 2024 - Install Jest, its types, and presets for Angular npm i --save-dev jest @types/jest jest-preset-angular · Create a setup-jest.ts file in your project’s root folder And add that single line of code in it: import 'jest-preset-angular/setup-jest';
🌐
Thymikee
thymikee.github.io › angular >=13
Angular >=13 | jest-preset-angular
March 29, 2026 - import type { Config } from 'jest'; import { createEsmPreset } from 'jest-preset-angular/presets'; import { pathsToModuleNameMapper } from 'ts-jest'; import { compilerOptions } from './tsconfig.json' with { type: 'json' }; export default { ...createEsmPreset(), transform: { '^.+\\.(ts|js|mjs|html|svg)$': [ 'jest-preset-angular', { tsconfig: '<rootDir>/tsconfig-esm.spec.json', stringifyContentPathRegex: '\\.(html|svg)$', isolatedModules: true, useESM: true, }, ], }, moduleNameMapper: { ...pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>' }), tslib: 'tslib/tslib.es6.js', }, setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'], } satisfies Config;
🌐
Medium
medium.com › @redin.gaetan › jest-and-angular-cb70ad78ee3d
Install Jest for Angular. A powerful combination, you should try… | by Redin Gaetan | Medium
October 3, 2021 - // package.json { ... "jest": { "preset": "jest-preset-angular", "setupTestFrameworkScriptFile": "<rootDir>/setupJest.ts" } ...
🌐
Dualboot Partners
dualbootpartners.com › home › insights › how to install jest and angular testing library
How to install Jest and Angular Testing Library
October 9, 2025 - (Optional) Create setup-jest.ts in the project root, for example indicating which levels of logs we want to be printed on the console when executing the tests.If you don’t want to add this file, you will need to remove the reference in jest.config.js file (previous step) [dm_code_snippet background=”no” background-mobile=”yes” slim=”no” line-numbers=”no” bg-color=”#abb8c3″ theme=”dark” language=”ruby” wrapped=”no” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]import ‘jest-preset-angular/setup-jest.mjs’; import ‘@testing-library/jest
🌐
Medium
medium.com › @abhijit_chikane › set-up-jest-in-angular-v20-project-zoneless-replace-karma-jasmine-5ddd5552f2cb
Set Up Jest in Angular(v20+) Project (Zoneless, Replace Karma & Jasmine) | by Abhijit Chikane | Medium
September 3, 2025 - npm install -D jest jest-preset-angular @types/jest jest-environment-jsdom @angular/platform-browser-dynamic · In the src/ folder, create a new file setup-jest.ts with the following: