question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript definition conflict, when including cypress types in create react app

See original GitHub issue

Current behavior:

When cypress types are included by tsconfig in cypress root folder and /// <reference types="Cypress" /> exists inside cypress integration spec, any reference to jest in a react component test eg expect() is overwritten and now seems to reference chai expect()

Also it looks like cypress is not able to pick up the types that have been defined inside its own tsconfig, hence the need for /// <reference types="Cypress" /> at the top of the test file see cypress/integration/app_spec.ts.

Desired behavior:

Any reference to jest in a react component test eg expect() is not overwritten. Cypress is able to pick up the types defined in its own tsconfig file.

Steps to reproduce:

git clone https://github.com/neiltownsley/react-typescript-cypress

yarn install

yarn start

App.test.tsx: (15,47): Property ‘toEqual’ does not exist on type ‘Assertion’. Did you mean ‘equal’?

yarn cypress open

cypress opens but can not resolve the domain because of compile errors.

When /// <reference types="Cypress" /> is removed from app_spec.ts

yarn start

app_spec.ts: (4,9): Cannot find name ‘cy’.


Versions

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
bahmutovcommented, Apr 19, 2018
1reaction
ppulweycommented, Aug 4, 2022

Ich had the same issue with Next.js. This tsconfig.json works for me

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "types": ["cypress", "node", "jest"]
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

solve conflict between jest and cypress in a react.js app with ...
There is a conflict occur in the react app after installing cypress with typescript I tried to follow the solution on the gitHub...
Read more >
TypeScript - Cypress Documentation
If you are using both Jest and Cypress in the same project, the TypeScript types registered globally by the two test runners can...
Read more >
Cypress - TypeScript Deep Dive - Gitbook
Create an e2e directory, install cypress, TypeScript and setup the typescript ... in this special e2e folder to prevent global type definition conflicts....
Read more >
JS/TS Tooling Overview
Overview of developer and build tools in the JavaScript and TypeScript ... with a wide ecosystem of plugins; used by popular tools like...
Read more >
Configuring Jest
Jest will run .mjs and .js files with nearest package.json 's type field set to module as ECMAScript Modules.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found