UI Testing

Run only a few / a single test

$ npx jest --help
  --testNamePattern, -t         Run only tests with a name that matches the regex pattern. [string]

$ grep describe dish-store.service.spec.ts
describe('DishStoreService Hase Horst', () => {

$ gnpx jest -t hase
 PASS  src/app/dishes/dish-store.service.spec.ts

Migrating from Karma to Jest

install deps
yarn add jest jest-preset-angular @types/jest --dev
jest.config.js
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig');

module.exports = {
  preset: 'jest-preset-angular',
  roots: ['<rootDir>/src/'],
  testMatch: ['**/+(*.)+(spec).+(ts)'],
  setupFilesAfterEnv: ['<rootDir>/src/test.ts'],
  collectCoverage: true,
  coverageReporters: ['html'],
  coverageDirectory: 'coverage/my-app',
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths || {}, {
    prefix: '<rootDir>/'
  })
};
src/test.js
import 'jest-preset-angular';

Object.defineProperty(window, 'CSS', {value: null});
Object.defineProperty(window, 'getComputedStyle', {
  value: () => {
    return {
      display: 'none',
      appearance: ['-webkit-appearance']
    };
  }
});

Object.defineProperty(document, 'doctype', {
  value: '<!DOCTYPE html>'
});
Object.defineProperty(document.body.style, 'transform', {
  value: () => {
    return {
      enumerable: true,
      configurable: true
    };
  }
});
Jest | TypeError: window.URL.createObjectURL is not a function #9889
npx jest  --unhandled-rejections=strict
remove karma part 1
 yarn remove karma karma-chrome-launcher karma-coverage karma-jasmine karma-jasmine-html-reporter