-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mocha type definitions conflict with @types/jest #6690
Comments
This has just started happening for me with the release of 4.3.0 (I'd skipped 4.2.0 due to #6752): https://travis-ci.com/github/textbook/starter-kit/jobs/309601851 |
4.2.0 doesn't have this issue, but it's happening to me too on 4.3.0. |
Im actually having this issue on 4.2.0. ¯\__(ツ)_/¯ TS 3.7.5 |
+1 bumped into this issue using 4.3.0 (also not working for me in 4.2.0)
Would recommend this thread for workarounds but it would be good to get an official fix for this |
Also running into this with the latest versions of Cypress and Jest. I've tried every workaround I've found in all of these issues/threads and nothing works. We're currently on slightly older versions of Cypress and we have to resort to a custom module and custom namespace with copy-pasted types just to get by. Upgrading to the latest Cypress packages breaks this horribly. Having Cypress and Jest in the same repo seems like a pretty common situation to me, so I'm surprised and annoyed that this is still an issue. |
@kaiyoma Also doing the copy pasted types thing to get by this for now. |
I also ran into this issue on Cypress 4.3.0. I have a blunt workaround that worked for me, which was to patch the Patch contentsdiff --git a/node_modules/@types/mocha/index.d.ts b/node_modules/@types/mocha/index.d.ts
index 10ee78a..45a1a2b 100644
--- a/node_modules/@types/mocha/index.d.ts
+++ b/node_modules/@types/mocha/index.d.ts
@@ -2731,7 +2731,7 @@ declare var suiteTeardown: Mocha.HookFunction;
*
* @see https://mochajs.org/api/global.html#beforeEach
*/
-declare var beforeEach: Mocha.HookFunction;
+// declare var beforeEach: Mocha.HookFunction;
/**
* Execute before each test case.
@@ -2749,7 +2749,7 @@ declare var setup: Mocha.HookFunction;
*
* @see https://mochajs.org/api/global.html#afterEach
*/
-declare var afterEach: Mocha.HookFunction;
+// declare var afterEach: Mocha.HookFunction;
/**
* Execute after each test case.
@@ -2765,7 +2765,7 @@ declare var teardown: Mocha.HookFunction;
*
* - _Only available when invoked via the mocha CLI._
*/
-declare var describe: Mocha.SuiteFunction;
+// declare var describe: Mocha.SuiteFunction;
/**
* Describe a "suite" containing nested suites and tests.
@@ -2786,7 +2786,7 @@ declare var suite: Mocha.SuiteFunction;
*
* - _Only available when invoked via the mocha CLI._
*/
-declare var xdescribe: Mocha.PendingSuiteFunction;
+// declare var xdescribe: Mocha.PendingSuiteFunction;
/**
* Pending suite.
@@ -2800,7 +2800,7 @@ declare var xcontext: Mocha.PendingSuiteFunction;
*
* - _Only available when invoked via the mocha CLI._
*/
-declare var it: Mocha.TestFunction;
+// declare var it: Mocha.TestFunction;
/**
* Describes a test case.
@@ -2814,14 +2814,14 @@ declare var specify: Mocha.TestFunction;
*
* - _Only available when invoked via the mocha CLI._
*/
-declare var test: Mocha.TestFunction;
+// declare var test: Mocha.TestFunction;
/**
* Describes a pending test case.
*
* - _Only available when invoked via the mocha CLI._
*/
-declare var xit: Mocha.PendingTestFunction;
+// declare var xit: Mocha.PendingTestFunction;
/**
* Describes a pending test case.
You put this patch into |
I am also running into this issue with Cypress 4.4. Is there a reason this isn't a peer dependency or is being redeclared and rewritten? |
we need to upgrade to the latest cypress (from 3.4.x) because of another bug, but this is blocking us |
This can repro with https://github.com/cypress-io/cypress-and-jest-typescript-example . (specifically, master is currently at commit cypress-io/cypress-and-jest-typescript-example@194918b ) The project doesn't have a webpack build, but running
Upgrading Cypress to latest (4.4.1) doesn't fix it. |
@sainthkh any thoughts on these type def conflicts also? |
The cause is easy to understand.
declare var test: Mocha.TestFunction; And declare var test: jest.It; Result: clash and error. But the problem is a bit hard to solve. Because types cannot be imported with a condition like "when @types/jest exist, import these, else, import those". And there is no official solution. TypeScript team answer is:
I guess |
I've been investigating and experimenting and came to conclusion that I need more information. With my current test setup and test command, Can anyone give me a repo that the clash didn't happen before 4.2.x or 4.3.x and happens after 4.2.x or 4.3.x? And tell me how to fix it? |
@sainthkh, here's the simplest possible Cypress setup that shows a difference between 4.2.0 and 4.3.0. Running this (in an empty subdirectory) works:
If you replace This setup does not even have any tests (either Jest or Cypress), it looks like simply installing (This is the situation I currently have - my Cypress tests are JS instead of TS, but I cannot update to Cypress 4.3.0 since it breaks other, non-Cypress-related TypeScript code in the same repo...) |
@pasieronen Thanks for the example. Confirmed and trying to find the solution. |
… to remove the dependency for now as it is not used anyway
I'm having similar problems, this, and also related to chai/bluebird, with the latest cypress. The fact that we are forced to include the third-party type references in the new versions means these sorts of type conflicts are kind of inevitable. it would be nice if the Cypress-specific types were a separate type which could be included on its own to avoid the type conflicts with other modules. Edit: Hm, seems older versions have the same issue. Giving up on using TypeScript with Cypress for now. |
Having the same. Jest tests show errors especially bad when used in combination with testing-library as this extends the expect object and expect command but Typescript uses the Mocha one instead |
There's a PR open to fix this here: #7194 |
@jennifer-shehane I'd like to try out the fix. Is it possible to reference that fork from my project? (or do I need to wait for it to hit It's apparently not as simple as referencing the branch in package.json 😐: - "cypress": "4.2.0",
+ "cypress": "sainthkh/cypress#issue-6690", |
@jrr The cypress folder inside |
The code for this is done in cypress-io/cypress#7194, but has yet to be released. |
the another ugly work around could be
|
The code for this is done in cypress-io/cypress#7352, but has yet to be released. |
The fix works for me! Cypress, Jest, and my build are all working with this version from |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior:
I'm running into an issue where the types defined for mocha, located at
node_modules/cypress/types/mocha
results in conflicts with types defined in@types/jest
. Below is are the details of one of the various errors that the typescript compiler reports:Below is a full list of the errors that appear in my IDE (VS Code):
Desired behavior:
Types do not conflict.
Test code to reproduce
Here's a small repo that demonstrates the issue. Errors can be seen by running
npm run tsc
.Forked test-tiny repo and was able to reproduce there as well.
Versions
Core packages needed to see issue are:
"@types/jest": "^25.1.4",
"cypress": "^4.1.0",
"typescript": "^3.8.3"
Current Workaround
Using approach described in this comment from #1319 .
The text was updated successfully, but these errors were encountered: