I want to implement some jest tests in my backend and so I was trying to map my paths that I have configured in tsconfig.json via the moduleNameMapper
of jest.config.js but when I run the tests I find the file is still not imported and I am shown this error on line 8 ⬇
Please assist me to map my paths correctly, I would highly appreciate any help.
To help you assist me here are the important files.
jest.config.js
(where jest is usually configured) ⬇
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ["**/***.test.ts"],
verbose: true,
forceExit: true,
moduleNameMapper: {
'@util/(.*)': '<rootDir>/src/util/$1'
}
};
tsconfig.json
(normal config file for typescript) ⬇
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"baseUrl": "src",
"paths": {
"@util/*": ["util/*"]
},
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}