Overview
I am currently transitioning a project from Angular.js to Angular, which involves migrating legacy unit tests from Karma and Jasmine to Jest. However, I am facing challenges with conflicting types between Jasmine and Jest in the project setup.
Issue
The problem arises when attempting to use both Karma/Jasmine and Jest simultaneously. The global environment ends up having duplicate functions, causing Jest tests to resolve to the Jasmine types. Removing Karma and Jasmine resolves the issue, but this is not an ideal solution.
Query
How can I exclude Jasmine types like 'expect' when running Jest without completely removing Karma and Jasmine from the project?
Attempts Made
In my attempt to address this issue, I created a separate tsconfig.spec file for Jest tests and referenced it in jest.config.js. I specified only the required types (node, jquery, jest) in the compiler options. Unfortunately, this did not prevent TypeScript from including Jasmine.
"compilerOptions": {
"types": ["node", "jquery", "jest"],
I also experimented with typeRoots in the tsconfig file, but encountered errors such as 'error TS2708: Cannot use namespace 'jest' as a value.'
{
"compilerOptions": {
"outDir": "../out-tsc/spec",
"typeRoots": [
"../node_modules/@types/jest"
...
],
"baseUrl": ".",
"paths": {
"*": ["./*"]
},
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"target": "es5",
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"allowJs": true
},
"files": ["polyfills.ts"],
"include": ["./app/**/*.spec.ts"]
}
I seem to be struggling to make TypeScript ignore node_modules/@types/jasmine. Any assistance or guidance on resolving this issue would be highly appreciated.