Background
I am working on a project that originated as a angular.js project. We are currently migrating everything to Angular. This means we have legacy unit tests for Angular.js which will eventually be removed. For Angular, we have migrated all tests to Jest.
Problem
The problem arises when trying to have both Karma and Jasmine
as Jest
in the project. The legacy unit tests are wired up with its own tsconfig file and these work fine. Both libraries seem to be adding the same functions to the global environment, and the Jest tests somehow keep resolving to the Jasmine
types. If I remove Karma and Jasmine
from the project all the tests work just fine.
Question
How can I can exclude jasmine's
types like expect
when running jest without removing karma and jasmine
from the project altogether?
I've tried
I have a seperate tsconfig.spec
file for the jest tests which I have referenced in the jest.config.js
file. In this I've tried adding the wanted types only. Which I thought would only load node_modules/@types/<included>
. But it will still include jasmine.
"compilerOptions": {
"types": ["node", "jquery", "jest"],
I've also tried including them through typeRoots
, but this only gives me more errors like: 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"]
}
Somehow I do not seem able to make TypeScript ignore the node_modules/@types/jasmine
. Any help or pointers would be greatly appreciated.
You can use jest-without-globals to explicitly import describe, expect, it, and test, overriding the global versions of these symbols which would otherwise be resolved from Jasmine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With