jest: doesn't seem to work with compilerOptions.paths option
See original GitHub issueAccording to this article, I have the following In my tsconfig.json:
projects/core/tsconfig.spec.json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"module": "commonjs",
"types": [
"jest",
"node"
],
"allowJs": true,
},
"files": [
"../../test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}
tsconfig.spec.json
// notice the paths
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"types": ["jest"],
"lib": [
"es2017",
"esnext.asynciterable",
"dom"
],
"paths": {
"@pwa/*": ["projects/pwa/src/app/*"],
"@mobile/*": ["projects/mobile/src/app/*"],
"@core/*": ["projects/core/src/*"],
"@auth/*": ["projects/auth/src/*"]
}
}
}
the .spec file has an import like this:
import { something } from '@core/some.service';
This results in an error:
Cannot find module ‘@core/some.service’ from ‘some.service.spec.ts’
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Typescript paths not resolving when running jest?
I wanted to resolve modules paths starting with ~/ to my <baseUrl>/<moduleName> . Thank to OJ Kwon link I solved it with (give...
Read more >Paths mapping | ts-jest - GitHub Pages
ts-jest provides a helper to transform the mapping from tsconfig to Jest config format, but it needs the . js version of the...
Read more >TSConfig Reference - Docs on every TSConfig option
All relative paths found in the configuration file will be resolved relative to the configuration file they originated in. It's worth noting that...
Read more >Typescript — How to solve the problem with unresolved path ...
This seems working OK in most of the cases, if all your source files and sub-folders are located under the same rootDir.
Read more >Typescript does not resolve modules through tsconfig.json's ...
So,it doesn't use settings in your tsconfig.json when compiling your files, it uses default TS options instead.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep, this is actually Jest’s problem. It doesn’t read the tsconfig.json neither does
ts-jest
. In fact, jest uses a bit different syntax for mappings. Check out this example, you have to add your mappings to your jest config undermoduleNameMapper
.Not angular-builders issue