Easy setup an Angular app with Jest Testing Framework
Angular CLI version 8.3.0
We are going to use Jest and jest-preset-angular for this..
- Step 1 : Remove Karma related stuff (almost everything that has to do with Karma from the package json and the app)
npm remove karma karma-chrome-launcher karma-coverage-istanbul-reporter karma-jasmine karma-jasmine-html-reporter
rm ./karma.conf.js ./src/test.ts
- Step 2 : Install Jest and jest-preset-angular
npm i -D jest @types/jest @angular-builders/jest
- step 3 : Update your Typescript configurations
In tsconfig.spec.json (src directory or project roots, used by Jest)
1 . Replace jasmine in types array with jest
2 . Remove test.ts from files array
3 . Add jest to types array
- step 4 : In angular.json change @angular-devkit/build-angular:karma to @angular-builders/jest:run
"projects": {
...
"[your-project]": {
...
"architect": {
...
"test": {
"builder": "@angular-builders/jest:run"
"options": {
... //see here
}
Now u can run the test
ng test
Some reference that might help :
Thymikee
Tran son
This is where i got more helps