Skip to content

Instantly share code, notes, and snippets.

@jonathas
Last active March 7, 2022 20:28
Show Gist options
  • Select an option

  • Save jonathas/b8962fadf419bc336ed9d1644d265267 to your computer and use it in GitHub Desktop.

Select an option

Save jonathas/b8962fadf419bc336ed9d1644d265267 to your computer and use it in GitHub Desktop.
moduleNameMapper mapping for Angular
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('./tsconfig.json');
const moduleNameMapper = Object.keys(compilerOptions.paths).reduce((acc, curr) => {
return {
...acc,
[curr]: '<rootDir>' + compilerOptions.paths[curr]
}
}, {})
module.exports = {
preset: 'jest-preset-angular',
globalSetup: 'jest-preset-angular/global-setup',
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/dist/', '<rootDir>/cypress/', '<rootDir>/src/test.ts'],
roots: ['<rootDir>'],
modulePaths: [compilerOptions.baseUrl],
moduleNameMapper,
collectCoverage: true,
coverageReporters: ['json', 'html', 'text', 'lcov'],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment