I'm attempting to add typeScript to a React project that uses javascript. I changed one class and the functionality works the same but several jest tests failed to run and had this error
Cannot find module 'pathtoclass/updatedTSClass' from 'jsClas'.
this is how I import the functional component
import updatedTSClass from '../../../path/path/updatedTSClass';
here is my tsconfig
"compilerOptions": {
"jsx": "react",
"lib": ["es2019", "dom", "dom.iterable", "esnext"],
"allowJs": true,
"checkJs": false,
"target": "esnext",
"noEmit": true,
"removeComments": true,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"strict": true,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"skipLibCheck": true,
"sourceMap": true
},
"include": ["./src/**/*"],
"exclude": ["./cypress/**/*", "./coverage/**/*", "node_modules"]
}
jest.config.js
module.exports = {
modulePaths: [
"<rootDir>"
],
globals: {
"ts-jest": {
"tsConfigFile": "tsconfig.json",
"enableTsDiagnostics": true
}
},
preset: 'ts-jest',
transform: {
'^.+\\.(ts|tsx)?$': 'ts-jest',
"^.+\\.(js|jsx)$": "babel-jest",
},
}
.babelrc
{
"presets": ["@babel/preset-react", "@babel/preset-env", "@babel/preset-typescript"],
"plugins": ["react-hot-loader/babel", "@babel/plugin-proposal-class-properties"]
}