After installing @types/jest
, I noticed that jest's corresponding typescript definitions were detected automatically. However, when I started implementing integration tests with cypress (which uses mocha), I encountered a problem where mocha type definitions were interfering with my jest tests. This led to overlapping type definitions and confusion, as both frameworks seemed to be defined in my project. Despite my attempts to create custom typings for functions like describe
to point to jest, mocha kept taking precedence.
How can I control the order of precedence for typescript definitions when multiple definitions are being detected?
https://i.sstatic.net/27HYn.png
The content of my tsconfig.json
file is shown below:
{
"compilerOptions": {
"target": "es5",
"lib": [ "dom", "dom.iterable", "esnext" ],
"types": [ "jest", "mocha" ],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": false,
"noEmit": true,
"jsx": "preserve"
},
"include": [ "src/**/*" ]
}
I also attempted another configuration as follows:
{
"compilerOptions": {
"target": "es5",
"lib": [ "dom", "dom.iterable", "esnext" ],
"typeRoots": [ "./node_modules/@types", "./src/types" ],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": false,
"noEmit": true,
"jsx": "preserve"
},
"include": [ "src/**/*" ]
}
Unfortunately, in both scenarios, mocha was prioritized over jest. How can I make sure that functions like "describe" are recognized as part of jest's type definitions and not mocha's?