Publisher : Admin
npm install --save-dev jest
2. Configure Jest : Create a
jest.config.js
file in the root directory of your project and configure Jest. A basic configuration for an Angular project would look like this :module.exports = {
roots: ['<rootDir>/src'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
};
package.json
file : "scripts": {
"test": "jest",
"test:watch": "jest --watch"
}
__tests__
directory in your project and write test files for your components and services. The test files should have the extension .spec.ts
.npm run test
__tests__
directory and display the results in the terminal. You can also run the tests in watch mode by using the test:watch
script.