I'm using the scoped path for types as @some-types. It's getting compiled fine, but when I'm testing components with imported modules, Jest can't find this module - ModuleA is undefined. I assume that something is wrong with jest config.
Type module example:
export module ModuleA {
...
}
Types modules exported with index.d.ts.
export { ModuleA } from "./ModuleA";
Usage of the imported module:
import { ModuleA, ... } from "@some-types";
tsconfig.json:
"paths": {
...
"@some-types": [
"src/types/index.d.ts"
],
}
jest.config.ts
export default {
globals: {
"ts-jest": {
babelConfig: true,
useESM: true,
tsconfig: "tsconfig.test.json"
}
},
collectCoverage: true,
coverageDirectory: 'coverage',
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'd.ts'],
moduleDirectories: ['node_modules', 'src'],
resetMocks: false,
setupFiles: ['jest-canvas-mock'],
moduleNameMapper: {
...
'^@some-types$': '<rootDir>/src/types/index.d.ts',
},
testEnvironment: 'jsdom',
transform: {
'^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
testPathIgnorePatterns: [
'/node_modules/',
'/lib/',
'/scripts/'
],
verbose: true,
};
P.S. The other scoped paths defined in moduleNameMapper as ^@hooks.(.*)$': '<rootDir>/src/hooks/$1' getting resolved fine.