If you wish to prevent TypeScript from type-checking your Jest tests, you can do either of the following:
#Using babel-jest as a Transformer
If you use babel-jest as a transformer to transpile TypeScript code into JavaScript, by default, it won't type-check your tests as they are run.
You can set it up in the following steps:
-
Install Relevant Packages
npm install --save-dev babel-jest @babel/core @babel/preset-typescript @babel/preset-env -
Specify Presets in Babel Configuration
// babel.config.js module.exports = { presets: [ ['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript', ], }; -
Set
babel-jestas Transformer in Jest Configuration// jest.config.js module.exports = { // ... transform: { '^.+\\.tsx?$': 'babel-jest', }, // ... }
#Using ts-jest as a Transform With isolatedModules
If you use ts-jest as a transformer to transpile TypeScript code into JavaScript, you can set it up in the following way to prevent it from type-checking tests:
-
Install Relevant Packages
npm install --save-dev ts-jest @types/jest -
Set
ts-jestas Transformer in Jest Configuration// jest.config.js module.exports = { // ... transform: { '^.+\\.tsx?$': [ 'ts-jest', { isolatedModules: true } ], }, // ... }Setting the
isolatedModulesoption totrueprevents type-checking when tests are run.
By default, ts-jest will type-check your Jest tests.