diff --git a/presets/index.js b/presets/index.js index 6104b86278..1e57687329 100644 --- a/presets/index.js +++ b/presets/index.js @@ -12,12 +12,6 @@ const basePreset = { '^.+\\.(ts|js|html)$': 'jest-preset-angular', }, moduleFileExtensions: ['ts', 'html', 'js', 'json'], - moduleNameMapper: { - '^src/(.*)$': '/src/$1', - '^app/(.*)$': '/src/app/$1', - '^assets/(.*)$': '/src/assets/$1', - '^environments/(.*)$': '/src/environments/$1', - }, snapshotSerializers, }; @@ -33,7 +27,6 @@ module.exports = { }, }, moduleNameMapper: { - ...basePreset.moduleNameMapper, tslib: '/node_modules/tslib/tslib.es6.js', }, transformIgnorePatterns: ['node_modules/(?!tslib)'], diff --git a/src/__tests__/__snapshots__/jest-preset.spec.ts.snap b/src/__tests__/__snapshots__/jest-preset.spec.ts.snap index dd31f9c01e..8b167ec2b8 100644 --- a/src/__tests__/__snapshots__/jest-preset.spec.ts.snap +++ b/src/__tests__/__snapshots__/jest-preset.spec.ts.snap @@ -14,12 +14,6 @@ Object { "js", "json", ], - "moduleNameMapper": Object { - "^app/(.*)$": "/src/app/$1", - "^assets/(.*)$": "/src/assets/$1", - "^environments/(.*)$": "/src/environments/$1", - "^src/(.*)$": "/src/$1", - }, "snapshotSerializers": Array [ "jest-preset-angular/build/serializers/html-comment", "jest-preset-angular/build/serializers/ng-snapshot", @@ -51,10 +45,6 @@ Object { "json", ], "moduleNameMapper": Object { - "^app/(.*)$": "/src/app/$1", - "^assets/(.*)$": "/src/assets/$1", - "^environments/(.*)$": "/src/environments/$1", - "^src/(.*)$": "/src/$1", "tslib": "/node_modules/tslib/tslib.es6.js", }, "snapshotSerializers": Array [ diff --git a/website/docs/getting-started/options.md b/website/docs/getting-started/options.md index 6929db85ff..0a38c90b8a 100644 --- a/website/docs/getting-started/options.md +++ b/website/docs/getting-started/options.md @@ -25,12 +25,6 @@ module.exports = { '^.+\\.(ts|js|html)$': 'jest-preset-angular', }, moduleFileExtensions: ['ts', 'html', 'js', 'json'], - moduleNameMapper: { - '^src/(.*)$': '/src/$1', - '^app/(.*)$': '/src/app/$1', - '^assets/(.*)$': '/src/assets/$1', - '^environments/(.*)$': '/src/environments/$1', - }, snapshotSerializers, }; ``` diff --git a/website/docs/guides/absolute-imports.md b/website/docs/guides/absolute-imports.md index cc54de8ac1..e679d83e3b 100644 --- a/website/docs/guides/absolute-imports.md +++ b/website/docs/guides/absolute-imports.md @@ -3,36 +3,7 @@ id: absolute-imports title: Absolute Imports --- -TypeScript supports absolute imports. The preset (starting from v3.0.0) by default understands absolute imports referring to `src`, `app`, `assets` and `environments` directory, so instead: +If you wish to use TypeScript path mappings which are defined in `paths` of your tsconfig, make sure that you create the +similar mapping for `moduleNameMapper` in Jest config. -```ts -import MyComponent from '../../src/app/my.component'; -import MyStuff from '../../src/testing/my.stuff'; -``` - -you can use: - -```ts -import MyComponent from 'app/my.component'; -import MyStuff from 'src/testing/my.stuff'; -``` - -However, if your directory structure differ from that provided by `angular-cli` you can adjust `moduleNameMapper` in Jest config: - -```json5 -{ - jest: { - moduleNameMapper: { - 'app/(.*)': '/src/to/app/$1', // override default, why not - 'testing/(.*)': '/app/testing/$1', // add new mapping - }, - }, -} -``` - -:::important - -If you wish to use any absolute import paths which are defined in `paths` of your tsconfig, make sure that you create the -similar mapping for `moduleNameMapper` in Jest config - -::: +More information see `ts-jest` [paths mapping](https://kulshekhar.github.io/ts-jest/docs/getting-started/paths-mapping) configuration documentation