geido edited a comment on issue #16792:
URL: https://github.com/apache/superset/issues/16792#issuecomment-930146850
### Cypress
I am not much of a Cypress expert and I am taking what I think are the most
relevant points for us from the official documentation, as well as adding some
thoughts from my times working with it.
#### Do not use Cypress :)
Do not use Cypress when RTL can do it better and faster. Many of the Cypress
tests that we have right now can be ported into RLT that is much faster and
gives a more immediate feedback. Cypress should be used mainly for processes
from A to B, B to C, etc. replicating the user experience, positive and
negative flows.
#### Isolated and standalone tests
Tests should never rely on other tests to pass. This might be hard when a
single user is used for testing as data will be stored into the database. At
every new test we should reset the database. This discussion goes a bit out of
the scope of the testing guidelines but might be worth pursuing.
#### Cleaning state
Cleaning the state of the application, such as resetting the db, or in
general any state that might affect consequent tests, should always be done in
the `beforeEach` hook and never in the `afterEach` one as the `beforeEach` is
guaranteed to run, while the test might never reach the point to run the
`afterEach`hook.
#### Unnecessary use of `cy.wait`
- Unnecessary when using `cy.request()` as it will resolve when a response
is received from the server
- Unnecessary when using `cy.visit()` as it resolves only when the page
fires the `load` event
- Unnecessary when using `cy.get()`. When the selector should wait for a
request to happen, aliases would come handy. For example:
```
cy.intercept('GET', '/users', [{ name: 'Maggy' }, { name: 'Joan' }]).as(
'getUsers'
)
cy.get('#fetch').click()
cy.wait('@getUsers') // <--- wait explicitly for this route to finish
cy.get('table tr').should('have.length', 2)
```
#### Resilience
Prefer `data-*` attributes to isolate selectors from eventual CSS, JS or
text content changes. Creating dedicated data selectors specifically for
Cypress might increase the boilerplate a bit but comes with the advantage of
being super resilient while making it apparent that the code is being tested.
For example:
`cy.get('[data-cy=submit]').click()`
Alternatively using text might work but it is not as resilient. For example:
`cy.contains('Submit').click()`
#### Materials:
https://docs.cypress.io/guides/references/best-practices
https://www.youtube.com/watch?v=5XQOK0v_YRE
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]