Skip to content

Instantly share code, notes, and snippets.

@wojtekKrol
Last active June 4, 2024 09:24
Show Gist options
  • Save wojtekKrol/1556f4ba5e00b9a581ca8377845c828e to your computer and use it in GitHub Desktop.
Save wojtekKrol/1556f4ba5e00b9a581ca8377845c828e to your computer and use it in GitHub Desktop.
Jest + TS + Path Aliases
import { pathsToModuleNameMapper } from 'ts-jest'
import { compilerOptions } from './tsconfig.json'
import type { JestConfigWithTsJest } from 'ts-jest'
const config: JestConfigWithTsJest = {
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/',
}),
preset: 'ts-jest',
resolver: 'jest-ts-webcompat-resolver',
}
export default config
{
"scripts": {
...,
"test": "jest",
},
"devDependencies": {
...,
"@types/jest": "29.5.12",
"jest": "29.7.0",
"jest-ts-webcompat-resolver": "1.0.0",
"ts-jest": "29.1.4",
"ts-node": "10.9.2",
"typescript": "5.4.5"
}
}
{
"compilerOptions": {
"paths": {
"~*": ["./*"],
...
},
"resolveJsonModule": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment