Angular Project Setup - NextensArelB/SwaggerGenerationTool GitHub Wiki

Create angular application npx ng new jest-example --directory ./ --routing --style=scss

Remove redundant packages npm rm karma karma-chrome-launcher karma-coverage karma-jasmine karma-jasmine-html-reporter jasmine-core @types/jasmine

Install jest npm i -D jest @types/jest jest-preset-angular ts-node

Initialize jest npx jest --init

โˆš Would you like to use Jest when running "test" script in "package.json"? ... yes โˆš Would you like to use Typescript for the configuration file? ... yes โˆš Choose the test environment that will be used for testing ยป jsdom (browser-like) โˆš Do you want Jest to add coverage reports? ... yes โˆš Which provider should be used to instrument code for coverage? ยป babel โˆš Automatically clear mock calls, instances and results before every test? ... no

Edit rootDir/jest.config.ts

export default {
  preset: 'jest-preset-angular'
  setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
  globals: {
    'ts-jest': {
      tsconfig: '<rootDir>/tsconfig.spec.json',
    },
  },
}

Edit rootDir/setup-jest.ts

import 'jest-preset-angular/setup-jest';

Edit rootDir/tsconfig.spec.json

{
  "compilerOptions": {
    "esModuleInterop": true,
    "types": ["jest"]
  },
  "files": ["src/polyfills.ts"],
}

Delete files

  • rootDir/src/test.ts
  • rootDir/karma.config.js

Run tests npm run test

โš ๏ธ **GitHub.com Fallback** โš ๏ธ