This project was generated with Angular CLI version 7.3.6.
To create the project, the following commands were used:
ng new angular-jest
cd angular-jest
npm remove @types/jasmine @types/jasminewd2 jasmine-core jasmine-spec-reporter karma karma-chrome-launcher karma-coverage-istanbul-reporter karma-jasmine karma-jasmine-html-reporter protractor
npm install -D jest jest-preset-angular @types/jest
rm -r e2e
rm src/test.ts src/karma.conf.js
and the following files have to be created:
module.exports = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/src/setupJest.ts']
}
{
"extends": "./tsconfig.json",
"compilerOptions": {
"esModuleInterop": true,
"types": [
"jest",
"node"
]
},
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}
import 'jest-preset-angular';
import './jestGlobalMocks';
Object.defineProperty(document.body.style, 'transform', {
value: () => {
return
enumerable: true,
configurable: true,
};
},
});
Finally modify the scriptspackage.json
to create a new job:
{
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"lint": "ng lint",
"test": "jest"
}
}
Now the jest can be run using npm test
.