I was able to resolve this with two steps.
- Install
@angular-builders/jestif not using latest version of angular you may want to specify the version ie if on angular 16 runnpm install @angular-builders/jest@16otherwise just anpm install @angular-builders/jestwill be enough - update the test.builder in angular.json config to use
@angular-builders/jest:run
my final angular.json test config looks as follows:
"test": {
"builder": "@angular-builders/jest:run",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json"
}
}
Answer from Derrick Awuah on Stack Overflow@angular-devkit/build-angular:jest Memory Leak and slower test execution speed on CI
Is Jest still going to be integrated officially with Angular?
Build unit tests specifically
unit testing - How to migrate from karma to jest in Angular 17 - Stack Overflow
I've been having a nightmare trying to reconfigure an old project's tests from Jasmine/Karma to Jest, because I have many coworkers advocating for it. But I'm surprised to see that while Karma has been deprecated for almost 2 years now, ng new and the refreshed Angular docs still only go over Karma, and make no mention of Jest or other testing frameworks at all https://angular.dev/guide/testing#other-test-frameworks.
This announcement https://blog.angular.dev/moving-angular-cli-to-jest-and-web-test-runner-ef85ef69ceca mentions @angular-devkit/build-angular:jest but I'm not sure if that's worth using - googling it actually points me to https://www.npmjs.com/package/@angular-builders/jest first but I'm not sure if this is something official.
jest-preset-angular also appears in lots of guides but it seems like every guide has a different way to set that up and I find its documentation kind of a nightmare of its own. Doesn't feel particularly futureproof.
Is Jest going to be a passing fad for Angular? Is there any news of deeper, documented integration anytime soon? Is Web Test Runner support at least close to being ready?
» npm install @angular-builders/jest