I am running unit tests in my C8Y application with Jest and I am noticing that the TS compiler is not recognizing the methods from the Jest framework and keeps underlying them in red.
-
If I hover overexpect
, it thinks that I am calling theexpect
method from the Chai framework. -
When I hover overit
, it thinks I am referring to theit
method from Mocha.
To be clear, I can still run the unit tests with npm test
and they work as intended.
This is only a problem when I try to build my application, as it reports them as errors and stops the build.
I have checked the configuration files for TS and Jest, and they seem to be in order.
ts.config.spec.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": ["jest"],
"esModuleInterop": true
},
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}
setup-jest.js
import 'jest-preset-angular/setup-jest';
jest.config.js
module.exports = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/setup-jest.js'],
transformIgnorePatterns: ['/!node_modules\\/lodash-es/']
};