Bad practices
Last updated
Was this helpful?
Last updated
Was this helpful?
You're not writing unit tests, don't be afraid to have a lot of asserts in an integration test
Cypress runs a series of asynchronous lifecycle events that reset state between tests and restarting tests is much slower than adding more asserts.
Avoid doing this type of test.
If you need more information about this, you can consult cypress documentation ().
In Cypress, it is almost never necessary to use cy.wait() for an arbitrary amount of time. If you find yourself doing this, there is probably a much simpler way. Usually a better implementation to avoid waits and implement stable tests is to make assertions (using should) based on the expected state of the control to validate.
The use of { force: true } should not normally be used to interact with components as it tends to omit checks that may not be representing the behavior you want to simulate or make some test unstable. An example would be to force click on a component that is not enabled and this check is omitted so the test would not be simulating real behavior.
These actions are not performed if you use forcing:
Scroll the element into view.
Ensure it is visible.
Ensure it is not disabled.
Ensure it is not detached.
Ensure it is not readonly.
Ensure it is not animating.
Ensure it is not covered.
Fire the event at a descendent.
Use should instead of then because cypress retries any assertion that is inside a should assertion. If then is used, it is validated only once. This avoids test instability because it takes into account the rendering time of the sample components. An Example:
Avoid using direct child selector (">") to refer controls or components on the UI, try to use whitespaces.
If you need more information about this, you can consult cypress documentation ().