-
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
Jest support #281
Comments
Mocha is definitely hard-coded into Cypress, although Mocha really only provides the testing structure and things like What would you gain from having Jest? The performance gains would be negligible, as Cypress is used mostly as an integration / e2e testing tool, and not so much unit testing. The vast (upwards of 99.99%) of compute time is spent driving the browser and loading the application, and Mocha does 0% of that. |
Thanks for the quick response.
|
I think the confusion comes because Cypress runs in the browser - not node.
|
@brian-mann There is an interesting argument for snapshots that I make in this article. It would certainly make that kind of testing a lot easier. |
I think the main problem is context switching. Jest/Jasmine and Mocha/Chai/(Insert Ten Thousand other plugins) style assertions are kind of close, but also very different. I hate having to write two different sets of tests, even though it's a minor gripe, anything that makes testing easier is a win in my book. |
I agree with @NoMan2000. Mocha, chai etc. just provide the testing environment and switching to jest in these terms wouldn’t provide much benefit, but cypress.io claims to be dependency free, which is just not true. If a project doesn’t use mocha you have to use it in your cypress code now. Having cypress independent of these or providing some kind of abstraction level (like That goes a long way to making it much more developer friendly |
IMHO this issue should be re-opened – the real value in supporting Jest with Cypress is in the lower context switch between writing assertions for E2E tests and unit tests as @NoMan2000 states #281 (comment). I don't think it's a minor thing; if you have hundreds or thousands of test cases to maintain across potentially multiple projects, saving yourself of one context switch can make a big difference. For unit tests, I don't know of any reasons why one would prefer Mocha + Chai + Sinon over Jest (easier to setup, faster, well documented, snapshot tests, better async support, built-in coverage) – so if one wants a single test definition style, it would be much better to consolidate on Jest than Mocha. Also relevant: #772. How does that sound @brian-mann? |
We have decided to reopen this issue. We have reevaluated this and decided it will be part of our future Roadmap. Things change quite a bit in 2 years. No work has been done for this. It is still in a proposal phase. |
Hiya, Jest team member here 👋 I'm not sure what concretely this issue entails, but if it's 'replace mocha with jest', note that Jest itself does not run in a browser. However, certain parts of it does:
Happy to field questions (and land changes in Jest) to help whatever you want to happen happen :) As an aside, I'd also love for us to be able to run Cypress tests on CI using Jest, e.g. https://twitter.com/kentcdodds/status/954200231393898496?s=19 |
Concretely from the OP, snapshots are hard as they use the file system. Might be we can make inline snapshots work, or use something like https://twitter.com/suchipi/status/1054249716194566145?s=19 to implement it |
Seems like you can call https://github.com/alexkrolick/cypress-test/blob/master/cypress/integration/index.spec.js |
Yeah, that's expected, it's not really a goal for Jest to report passing expectations. That might change in the future, though: jestjs/jest#6616. BTW, if it was unclear, |
Do you have an updated estimate when/if this is going to be added? |
This issue is still in the 'proposal' stage, which means no work has been done on this issue as of today, so we do not have an estimate on when this will be delivered. |
Personally I would like to see jest support in cypress for the main reason that I can use same matchers that i have in my UT. When testing with cypress I do not care about snapshot testing as this shouldn't be done when doing e2e/integration testing. Right now is very confusing and it adds extra effort when writing tests as my UT are done using Jest matchers and cypress uses chai matchers. |
I just created a simple small package to add Jest expect matchers and syntax to run with Cypress and Chai-based reporter here: https://github.com/phongnd39/cypress-jest-adapter. The mock assertions functions are still based on Chai-Sinon, though. I do hope that Cypress add jest support out-of-the-box or give an option for us to choose the testing framework soon. |
Hey @phongnd39, can you add your plugin to our docs on the plugins page? |
Hi @jennifer-shehane , I have created a pull request to Cypress plugins pages. Can you help me review it? |
I have just updated my package https://www.npmjs.com/package/cypress-jest-adapter with some new assertion methods to assert elements returned from Cypress command more quickly. Can do assert like |
Looking forward to Jest implementation myself coming from Vue CLI. |
Following this thread. Consider this a +1 for the feature/issue @jennifer-shehane 🙏 |
To add to @TheJaredWilcurt's comment, Jest seems much more popular considering downloads, forks, and contributors compared to mocha and chai. However, I get it if you need to wait for a new Jest api jestjs/jest#6616 (comment). I'm just trying to say that the effort wouldn't be wasted on an issue like this as Jest is carrying significant momentum. Source: npmtrends jest vs mocha vs chai |
Any news on this? I think that a lot of people are eager for Jest support. Just a 👍 on what everyone is saying above. Also, not thinking about this out of the box will always be a bit weird. For example - the latest release of 4.6.0 has a pretty cool inline source map error reporting built in. However, when using the Jest Adapter Plugin - the errors look like this when doing an expect like so:
|
I am evaluating Cypress for our Angular development team. Since we are using Jest for unit testing, this issue is of great interest. It is certainly not ideal if we must use Mocha/Chai/Sinon APIs for E2E Testing and Jest APIs for unit testing, due to context switching and the need to learn two APIs. That need not necessarily stop us from adopting Cypress, but it will certainly be a negative factor in the evaluation. |
We adopted Cypress despite the fact that it uses Mocha. We love the framework, but I would be lying if I said that having to know Mocha and Jest wasn't a significant source of friction 😬 |
Would really appreciate if there was an example using Ava import test from 'ava';
test('Page exists', async (t) => {
cy.visit('/').then(async function({ document: { body } }) {
t.true(body.includes('<h2 class="mt-6 text-2xl font-extrabold leading-9 text-center text-gray-900">Welcome</h2>'));
done();
});
}); something like this?! |
There are some projects using Jest & Cypress integration: https://github.com/bahmutov/cypress-and-jest Can we consider as a Jest support or it isn't official? |
I'm highly interested in this feature as I can't live without Jest |
So I suppose comments are needed to increase priority on this. Here's one. |
It would be amazing to have jest in Cypress. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
If you have interest in this feature, please add a 👍 emoji to the main comment of the issue. If you have some more substantial comments to make about how the feature should be implemented, please leave a comment. Otherwise the comments become a lot of noise for others following the issue. Thanks! |
This comment has been minimized.
This comment has been minimized.
I think there is a significant interest to have jest support in Cypress. Is it possible to add it to the roadmap and get an ETA for it? |
I've noticed that TypeScript begins to get finicky with projects that use both Cypress and Jest. I'm presently trying to figure out how to properly juggle Jest and Mocha types in the correct folders. Would first-party Jest support solve this? If there were, say, some way to configure Cypress to utilize Jest types and constructs, rather than Mocha's, I expect typing issues like these would disappear. |
@AverageHelper you can handle conflicting global types by making a separate tsconfig.json for your cypress folder, then you can use project references |
Been working on that today. Still juggling. I've got my root tsconfig set up to reference other tsconfig files that themselves define the file blobs to which they should apply, each also inheriting common config options from a separate base tsconfig file. My Cypress folder has its own tsconfig file, referenced in the root one as a separate project. Now everything except my Cypress files has type conflicts 😅 EDIT: Got it. It just took a bunch more juggling 😁 |
I am in a similar situation trying to get TypeScript to work with both Jest and Cypress/Mocha. The examples provided assume a
Using project references for this would work if it was just loading a web page in the cypress test, but as soon as you start importing say So if I could remove the need for project references by using Jest for both unit and integration tests, that would be 👨🍳 😗 |
2021 still we are expecting jest to be incorporated with cypress . |
We don't require Jest, Mocha does the job successfully! |
Although I also voted for this issue, this is still an open-source project which leaves you with the following options:
Commenting and "expecting" others to solve this issue is imho not the way to go. Please let's focus with regards to content. |
I suppose there is also the option to pay someone to add the feature. |
Jest has surpassed mocha in terms of performance as well as some features (snapshot testing specifically).
Is mocha hard-coded to Cypress or is it possible to have support for Jest in the not too distant future?
The text was updated successfully, but these errors were encountered: