npmtypescript95% confidence\u2191 135

Cypress causing type errors in jest assertions

Full error message
I had been using react-testing-library as well as @testing-library/jest-dom/extend-expect. I installed Cypress yesterday, and now I'm getting Typescript errors on all my jest matchers:

Property 'toEqual' doesn't exist on type 'Assertion'. Did you mean 'equal'?

It looks like it's getting the type of expect from the wrong assertion library or something? Also, expect(...).to.equal(...) doesn't even work either.

I actually tried installing @types/jest and yarn appears to have succeeded but it's not listed in my package.json's devDependencies. 

Here's my tsconfig

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "noImplicitAny": false,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": false,
    "noEmit": true,
    "jsx": "react",
    "skipDefaultLibCheck": true,
    "types": [
      "node",
      "cypress",
      "jest"
    ]
  },
  "include": [
    "src"
  ]
}

I'll also mention that all my cy calls in my cypress tests are getting a cy is not defined error from ESLint.

Anyone facing this problem in the github issue "New Cypress 10 global TypeScript type conflicts with Jest expect" has a workaround Fix issue by exluding ./cypress.config.ts in your tsconfig.json "exclude": [ "./cypress.config.ts", //other exclusions that may help https://github.com/cypress-io/cypress/issues/22059#issuecomment-1428298264 "node_modules", "cypress", "**/*.cy.tsx" ] From cypress developer: We didn't change our globals very much for v10. For all the cases I reproduced, it was fixed by adding ./cypress.config.ts to the tsconfig.exclude property. Since the cypress.config.ts is being included in the type checking, it is loading the cypress types which is polluting your jest tests.

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/cb1f6ba6b7c780d03f27d647966d30fbd3d3b5cdc133057a060e2fe0cf26689e
hash \u00b7 cb1f6ba6b7c780d03f27d647966d30fbd3d3b5cdc133057a060e2fe0cf26689e
Cypress causing type errors in jest assertions — DepScope fix | DepScope