Skip to content

Jest

Create jest.config.ts in your project root:

import type { Config } from 'jest';
import baseConfig from '@presencelearning/frontend-config/jest';
export default {
...baseConfig,
// Customize module name mappings for your project
moduleNameMapper: {
...baseConfig.moduleNameMapper,
'@my-alias/(.*)': '<rootDir>/src/my-path/$1',
},
} satisfies Config;

The base config sets setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'], so you must create that file — an empty one is fine to start. Without it the first run fails with a module-not-found error. The shipped MSW template at msw-templates/jest-global-mocks.ts is a good starting point; copy it to jest.setup.ts and fill in the server import it stubs out. It pulls in jest-location-mock and whatwg-fetch, which you install yourself.

  • jest-preset-angular configuration (the CJS preset, not ESM)
  • jest-fixed-jsdom test environment, with customExportConditions: [''] so MSW resolves correctly
  • MSW (Mock Service Worker) compatible
  • Coverage reporting to test-results/unit-coverage, collected from src/app/** and src/lib-components/**
  • lodash-eslodash and chart.js module mappings
  • Ignores <rootDir>/projects and <rootDir>/ui-tests
  1. Backup your jest.config.js
  2. Create new jest.config.ts importing the base config
  3. Copy custom moduleNameMapper entries
  4. Remove redundant settings (already in base config)

Update moduleNameMapper in your jest.config.ts to match your tsconfig.json paths.