0

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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

thanks this is good to know and I will use this in my personal project, however, my works project is too far gone for this to ever work - ill have to try and hack it - but much appreciated
1
  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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.