-
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
New Cypress 10 global TypeScript type conflicts with Jest expect
#22059
Comments
WorkaroundsWorkaround 1Use // Cypress adds chai expect and assert to global
// declare const expect: Chai.ExpectStatic
declare const assert: Chai.AssertStatic Then add back the declare const expect: Chai.ExpectStatic; Workaround 2Use import { expect } from 'local-cypress'; |
expect
expect
Hello, We also have this problem with Karma/Jasmine on Angular. Do you have any informations on if and when you will fix that issue ? The workarounds aren't clear enough to be honest, and they are "workaround" anyway which isn't really good. It's kinda "critical" I think 😄 Have a good day! |
@karlhorky thanks for posting, looks like you're not the only one having issues with Cypress + Jest type collisions. I was able to reproduce this with the repos linked @karlhorky @mrdrogdrog @wKovacs64. When I checked out the dep update to v10, all of the Jest tests started complaining. We didn't change our globals very much for v10. For all the cases I reproduced, it was fixed by adding |
Hello @ZachJW34, Edit: removed the old message, I misread your answer, it indeed work, thank you! |
This worked for me, thanks @ZachJW34 ! |
|
@marktnoonan @ZachJW34 @mjhenkes should we leave this one open so that the documentation page mentioned in the issue description is updated? |
Thank you for sharing this @ZachJW34 , but this seems does not work for me, maybe you could help me. I still see errors which is listed at very first messge structure:
|
@karlhorky @ZachJW34 Thanks for all your input here We had the same issue blocking our upgrade to v10. Adding I would also like to echo that this issue be elevated to the v10 migration guide or made much clearer in the documentation please. It is very difficult to diagnose and remedy without any pointers. Thanks |
I've created cypress-io/cypress-documentation#4559 against the docs repo so that we can document the solution there. Thanks everybody for reporting and providing examples, and @ZachJW34 for pointing out the right step to take. Good point @arelra about maybe mentioning this in the Migration Guide and as part of migration itself, we will consider both. Going to keep this issue open a little longer since it does seem like we somebody for whom |
Note: I also had to add |
@kuantayevs what worked for me in my monorepo structure was to add the {
"exclude": [
"packages/fusion.upleveled.io/cypress.config.ts",
]
} Adding to the |
@SchroederSteffen why did you need to do this? (eg. what were the details of what was happening without this change?) I didn't need to do this, but maybe I and others would want to for some reason... |
expect
expect
Yes, sorry for not clarifying! 🤦♂️
Note: Our ESLint config selects files as follows:
|
Oh fancy, didn't know that about the |
This is still an issue with a brand new install of Angular and cypress as of 7/12/2023.. Is there an official fix/documentation "dependencies": { |
Other than adding I think Cypress should have a frontend module bundle that does import { expect, cy, Cypress, describe, it } from 'cypress' as suggested above in this post: #22059 (comment). It looks like there is already a package that partially implements this: https://github.com/bahmutov/local-cypress#readme Even if these are dynamically injected at runtime, the exports should just be type safety wrappers and no-ops, in the same way `import { defineConfig } from 'cypress' is a no-op at runtime - it just adds type safety. I am unsure on the complexity of this or if we are looking to implement this soon. Is someone interested on working on this? If so, I can propose this internally to our product team to get requirements (if we decide to prioritize it). |
@lmiller1990 Regarding your last comment, maybe https://www.npmjs.com/package/@jest/globals can be a point for inspiration. I’m using this package to avoid globally typing "Jest globals" and it works very well. |
This is very frustrating. I think I don't want to install cypress into my Angular project, but I want to do Component testing. Very hard to bring this to my team, when it break all the asserts for our unit test. Let us make sure also our custom commands still work with this implementation, etc. I notice I get one thing working, then it breaks something else. WE CAN NOT ACCEPT INSTALLING THIS package if it breaks our unit test asserts. I AM VERY SUPRISED this was allowed to get past QA at cypress. I give a lot of grace, but this is breaking a brand new angular project with YOUR INSTRUCTIONS. I guess I am frustrated because I really want to use component testing, but I think I will separate my MY CYPRESS project from my Angular project so they do not collide AND NOT DO COMPONENT TESTING. All I ask is you follow your own instructions and see it breaks. Just do a simple NG new my-project and then install cypress, RIGHT OUT THE BOX IT IS BROKE.. |
Please does somebody have a fix about this one? The latest version brought back this issue. |
The problem is multiple tools declaring matching globals. This issue could be opened in Jest and be just as relevant. It looks like Jest has a module API that exposes these: https://jestjs.io/docs/api import { expect } from '@globals/jest' There is also something similar via Surely this combination could let you both import { expect } from '@jest/globals'
import { expect } from 'local-cypress' Or you can use /// <reference types= "cypress" /> For Cypress files. These are the workarounds suggested above, too: #22059 (comment). Have you tried these, @etsraphael? @maccurt can you try these? There is no magic way to make it work, you'll need to make sure each spec file knows which test runner / tool it's associated with. It doesn't look like you've tried that yet. Give one of these a try, it should fix your issue. As an aside, I don't know why any framework still uses global variables. I have run into this too, but the reality is if there are multiple types assigned to the same variable (eg I'm not sure if there's any edge cases with |
@lmiller1990 I will give that a try |
Please see our docs for recommendations on how to avoid clashing. Docs were updated in this PR: cypress-io/cypress-documentation#5514 We investigated ways to automatically avoid this in our product, but didn't come to a clear solution unfortunately. |
It's still not working for nrwl/nx monorepo. and repo here |
I am stuck here at the moment too. I wanted to experiment having my Cypress integration tests for Next pages alongside the implementation and the Jest unit test file.
using
but I can only seem to get either the Jest file OR the Cypress file to be happy, but not both.
|
This is how I "solved" it fin my repo (example above). I have an extra complication in that I had also extended the cy object via
Not ideal as it means adding the reference to each file, but it isn't the end of the world. |
If you want to have Cypress tests next to Jest tests in the same folder, you can use the following config as a template (please adjust paths to your folder structure). This solution relies on project references:
|
Current behavior
The following new global TypeScript type for
expect
innode_modules/cypress/types/cypress-expect.d.ts
causes conflicts with Jestexpect
types, if a project has both Jest and Cypress:cypress/cli/types/cypress-expect.d.ts
Line 2 in a0a64cc
Errors:
When looking through the docs, there is a guide here:
Cypress Types Conflict with Jest
However, this guide is based on the fact that Cypress types were not global before (but they are now).
Desired behavior
No response
Test code to reproduce
Jest test code (filename
__tests__/colors.test.ts
):Cypress Version
10.0.1
Other
No response
The text was updated successfully, but these errors were encountered: