New Cypress 10 global TypeScript type conflicts with Jest `expect`
See original GitHub issueCurrent behavior
The following new global TypeScript type for expect
in node_modules/cypress/types/cypress-expect.d.ts
causes conflicts with Jest expect
types, if a project has both Jest and Cypress:
Errors:
Property 'toBe' does not exist on type 'Assertion'.

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
):
import { findWhiteContrastingColor } from '../colors';
test('findWhiteContrastingColor finds colors contrasting with white', () => {
expect(findWhiteContrastingColor(['#ffffff', '#000000', '#e1e1e1'])).toBe(
'#000000',
);
});
Cypress Version
10.0.1
Other
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:53
- Comments:36 (12 by maintainers)
Top Results From Across the Web
Cypress causing type errors in jest assertions - Stack Overflow
I ran into this problem yesterday. It seems that what you are saying is correct, cypress and jest both declares types for expect...
Read more >Cypress and Jest `expect` functions conflict in IDEA, tests ...
Cypress and Jest `expect` functions conflict in IDEA, tests execute fine on the command line. This problem has a bit of relevance to...
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 >How to Avoid Using Global Cypress Variables - Gleb Bahmutov
Both Cypress and Jest provide global variables like describe and expect for your tests to use. The global variables do not clash at...
Read more >Cypress - TypeScript Deep Dive - Gitbook
It is best to keep the e2e tsconfig.json and node_modules in this special e2e folder to prevent global type definition conflicts.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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
./cypress.config.ts
to thetsconfig.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../tsconfig.json
, includetypes
andexclude
properties in config file.cypress/tsconfig.json