I have this component:
import React from \'react\';
import VideoTag from \'./VideoTag\';
import JWPlayer from \'./JWPlayer\';
class VideoWrapper extends React.C
I also had to add the moduleNameMapper
to my jest configuration for my tsconfig path maps in order to get my tests to recognize the path maps I had setup. Something like this:
"moduleNameMapper": {
"^yourPath/(.*)": "<rootDir>\\yourPath\\$1"
}
Hopefully this will help someone down the line!
The problem were not the paths, It was looking for modules only with .js extension, it worked after adding the .jsx in the jest configuration:
"moduleFileExtensions": [
"js",
"jsx"
]
For others ending up here trying to use Jest with TypeScript: you need to include ts
in the moduleFileExtensions
, e.g.:
"moduleFileExtensions": [
"js",
"jsx",
"json",
"node",
"ts"
]
You also need a transform for *.ts
files:
transform: {
"^.+\\.vue$": "vue-jest",
"^.+\\.js$": "babel-jest",
"^.+\\.(ts|tsx)$": "ts-jest"
},
In my case the issue was the import
is also case sensitive. Check your import
statement and ensure that it matches the filename exactly!
You don't need to add moduleFileExtensions in the configuration for these two options since jest uses ['js', 'jsx', 'json', 'node'] as default file extensions. (Unless you want to specifically skip any option that is)