C8Y application does not recognize Jest functions

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.

  1. image
    If I hover over expect, it thinks that I am calling the expect method from the Chai framework.

  2. image
    When I hover over it, it thinks I am referring to the it method from Mocha.

To be clear, I can still run the unit tests with npm test and they work as intended.
image

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/']
};

Hi Lucas,

do you have Cypress installed in the same project?

Best regards



Christian Guether

Hi Lucas.

this is not really an issue with it being a Cumulocity Web SDK application, but a general issue when using cypress and jest on the same project. The comment over here: New Cypress 10 global TypeScript type conflicts with Jest `expect` · Issue #22059 · cypress-io/cypress · GitHub might help you.

Regards,
Tristan

2 Likes

Hi Tristan, thanks for the input.

I was able to solve it with the suggestion posted here.

1 Like