I have pretty straightforward question: "How to configure typescript with jest". I know that there are plenty resources for this. But no one solution worked for me.
Here is my jest.config.js:
module.exports = {
roots: [
'<rootDir>'
],
transform: {
"^.+\\.ts$": "ts-jest"
},
testMatch: ['<rootDir>/tests/**/*.ts'],
moduleFileExtensions: ['ts', 'js'],
modulePaths: [
'<rootDir>/src/js/'
],
moduleNameMapper: {
'Services(.*)': '<rootDir>/src/js/$1'
},
};
First problem is that module name mapper does not work. I added both modulePaths and moduleNameMapper but no one works. It just simple says: "Can not find module ...".
Another problem is that when I fake module name mapper (for example 'i': '<rootDir>/src/js/State.ts' and make it work, I have " Unexpected token export". But I followed this guide https://basarat.gitbooks.io/typescript/docs/testing/jest.html and I have the same code as on that example. I tried using babel for jest - the same.
Of course, I tried googling. But no success. I tried different ways - no result. I spent almost 2 hours on it. I know that there should be a simple solution for this as jest and typescript are popular packages.
Update: Here is my tsconfig.js
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"module": "es2015",
"target": "es5",
"jsx": "react",
"allowJs": true
}
}