Skip to content

jvaler01/angular-test-jest

Repository files navigation

AngularTesting

This project was generated with Angular CLI version 13.2.5.

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Code scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory.

Angular testing with JEST

  1. Remove any reference to Jasmine / Karma in the package.json
npm remove <karma karma-chrome-launcher...>
  1. Install Jest
npm install --save-dev jest jest-preset-angular @types/jest
  1. Create the setup-jest.ts file in the root folder of the project with the following content
import 'jest-preset-angular/setup-jest';
  1. In the package.json add the following configuration
"jest": {
    "preset": "jest-preset-angular",
    "setupFilesAfterEnv": [
      "<rootDir>/setup-jest.ts"
    ],
    "globalSetup": "jest-preset-angular/global-setup"
  }
  1. Configurate JEST in tsconfig.json and tsconfig.spec.json
"types": [
  "jest"
]
  1. Configure the commands to run the tests in the package.json
"test": "jest",
"test:watch": "jest --watchAll",
  1. Remove karma.config.js and the test.ts file

About

Testing angular with Jest

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published