Testing React Apps in 2022 with Cypress: An In-Depth Guide for Beginners
profy.dev
profy.dev
I can’t be clearer than that.
It’s got a lot of frustrating edge cases and problems that mean your tests will always be brittle and break. A short list of the issues I’ve personally found is:
- they invented their own non compliant promises spec that means you can’t use async functions or methods.
- the 1st party xpath plug-in is not fully implemented and fails to have a sub selector (get xpath in this element).
- the runner doesn’t support individual tests in the ui, only test groups
- the plug-in ecosystem is weak, and many plugins only work with “happy path” scenarios, meaning you have to fork them to fix bugs
- you can’t catch a failed promise and try something else (see stupid promises implementation) meaning it’s always a hack to have a fallback test
- I can’t even begin to describe how frustrating the ‘.wrap()’ api is. The people who wrote this used jquery as their programming model, and it shows. Every object gets a magical wrapper to use the magical cypress functions, but promises sometimes return objects not wrapped objects. Your code starts looking very familiar if you alias “cy.wrap” to “$”.
It’s pretty, it’s smooth for trivial tests. …but do you need trivial tests?
Probably, you don’t need trivial tests. For trivial things, you can use unit tests.
Cypress makes it easier to throw away your tests and write them again than it does to maintain the ones you have.
what does one thing has to do with the other, please elaborate
> the 1st party xpath... > runner doesn’t support individual tests...
seem minor
> sometimes return objects not wrapped objects
sounds like lodash chaining, which is fine once you understand the library
> the plug-in ecosystem is weak
big deal? I use a tool like cypress for itself, not plugins, whatever they do
I get it, the tool isn't perfect and has things you don't like, but I don't see how this warrants a "do not use", seems pretty disproportionate
(Prefer other types of tests whenever possible, but if you really do need drive-the-entire-browser E2E tests, use Playwright[1]. It's years ahead of Cypress.)
If you're considering Cypress for test automation, I would really suggest giving Playwright a go. It fixed many of the pain points I had with Cypress. Even just tabbing in Cypress requires a plugin, where as it's supported natively in Playwright.
The endless polyfilling to make a node env removes some of the before of the test imo.
I haven't done JS for awhile, but according to https://docs.cypress.io/api/commands/type#Events they still don't support it. The docs point you to a third party package that tries to simulate it inside the page.
Im interested in Playwright, but wondering how you find the visual runner compared to Cypress? Are you able to run your tests in the browser and use a `debugger` or dev tools?
Why not use playwright?
Should you in the unfortunate case and need to use cypress, you can use https://sorry-cypress.dev/ ! Because cypress is/was open, someone just build a dashboard alternative to their business model.
I don't have any strong opinion about the end-to-end testing tools though, but some mentioned Playwright is a better alternative if you are looking for e2e testing.
I’m looking for pitfalls, edge cases, special features, performance optimization, that kind of thing.
React Testing Library is good if you want to unit test individual components.
They both have their uses.
[0] https://youtube.com/playlist?list=PLC2LZCNWKL9bLQrMQKfTnpihg...
It's a massive pain in the ass.