danday74
danday74

Reputation: 57036

Angular configuration when using Jest

I've recently switched to Jest for unit testing

Previously I was doing this:

ng test --configuration=unit-tests

But I am not sure how to run my Jest tests with an Angular configuration, I want something like this:

jest --configuration=unit-tests

How do I run my Jest tests with a specified Angular configuration?

Upvotes: 0

Views: 732

Answers (2)

Sumith Ekanayake
Sumith Ekanayake

Reputation: 2265

  1. Created a setupJest.ts file in the root and import jest-preset-angular
  2. add the Jest configuration in the package.json

"jest": {
    "preset": "jest-preset-angular",
    "setupFilesAfterEnv": [
      "<rootDir>/setupJest.ts"
    ]
  }

  1. modify the test script to use Jest instead of ng test.

  2. run npm test

Upvotes: 1

vitaliy kotov
vitaliy kotov

Reputation: 647

In angular.json file specify jest runner for test architect:

"test": {
   "builder": "@angular-builders/jest:run",
   "options": {}
},

I assume that you have installed it, when switched to jest

Upvotes: 1

Related Questions