I am relatively new to TypeScript and JavaScript, so I have a question regarding the necessity of preprocessing modules like ts-jest for running Jest tests with TypeScript code. Currently, I am working on a TypeScript project in Node and everything seems to be functioning well with Jest without the use of ts-jest.
My approach involves transpiling both my TypeScript code and tests into ES5 JavaScript before running them with Jest, which has been effective so far. This begs the question - why would one need to use ts-jest? In what scenarios would it be advantageous?
I have come across suggestions like the one mentioned here, advising the use of ts-jest to "preprocess typescript files". However, this concept is unclear to me as I believe that TypeScript handles such tasks inherently. Hence, I do not see the necessity for using ts-jest.
Perhaps I am missing:
- The distinction between transpilation and pre-processing
- The significance of Jest's transform property
Below is a snippet from my tsconfig.json file:
{
"compilerOptions": {
"strictNullChecks": true,
"noImplicitAny": true,
"moduleResolution": "node",
"target": "es5",
"lib": [
"es6"
]
},
"include": [
"src/**/*",
"test/**/*",
],
}
And here's a glimpse at my package.json configuration:
{
"scripts": {
"test": "jest",
"dev": "nodemon ./src/app",
"start": "node ./src/app"
},
"devDependencies": {
"@types/express": "^4.16.0",
"@types/jest": "^23.1.1",
"jest": "^23.1.0",
"nodemon": "^1.17.5"
},
"jest": {
"transform": {},
"testRegex": "/test/.*\\.(ts|tsx|js)$"
}
}