Cypress Best Practices
- Give your stubs an alias and use
.wait()
to ensure they’re resolved before trying to make assertions against what you expect on the DOM
- Combine assertions for related flows into a single ‘it’ block to help Cypress be more performant. Do not break out each piece of functionality into it’s own ‘it’ block - this causes the beforeEach code to run unnecessarily and negatively impacts performance
- Don't put stubs (and other functionality) in the beforeEach unless its absolutely required for every single it block. Otherwise its a waste of processing power.
- Don’t leave Cypress open and running when you’re not working on testing. Close it and re-open as needed.
- Close down other unneeded windows and tabs. If you have a bunch of stuff running all at once, it will impact the speed and performance of Cypress
- Read and make note of the Best Practices outlined in the Docs
Things To Try If Cypress is giving you trouble with slow or inconsistent behavior:
- Try the electron browser in the Cypress UI
- Close and re-open Cypress
- Restart laptop
- Clear cypress cache (see docs) will need to re-install cypress after
- Use built in memory and CPU usage logger (see docs)