Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SebastianCB-dev/dccc5be8a3f27cdc31b82448de32a702 to your computer and use it in GitHub Desktop.
Save SebastianCB-dev/dccc5be8a3f27cdc31b82448de32a702 to your computer and use it in GitHub Desktop.
Angular 13+ Configure Jest Testing

Angular testing con JEST

  1. Remover cualquier referencia de Jasmine / Karma en el package.json
npm remove <karma karma-chrome-launcher...>
  1. Instalar Jest
npm install --save-dev jest jest-preset-angular @types/jest
  1. Crear el setup-jest.ts en la carpeta root del proyecto y el contenido es el siguiente
import 'jest-preset-angular/setup-jest';
  1. Agregar en el package.json, la configuración de Jest
"jest": {
    "preset": "jest-preset-angular",
    "setupFilesAfterEnv": [
      "<rootDir>/setup-jest.ts"
    ],
    "globalSetup": "jest-preset-angular/global-setup"
  }
  1. Configurar JEST en tsconfig.json y tsconfig.spec.json
"types": [
  "jest"
]
  1. Configurar los comandos para ejecutar las pruebas en el package.json
"test": "jest",
"test:watch": "jest --watchAll",
  1. Remover karma.config.js y el archivo test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment