I was writing end-to-end tests for TripTime’s authorisation function, and as the system will block user from registering a new account if the email is occupied, I used the conditional testing feature offered by Cypress.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.get('body')
.then($body => {
if ($body.text().includes('Sorry')) {
cy.get('header')
.contains('Log In')
.click()
.get('[type="email"]')
.type('new-user@cypres.com')
.get('[type="password"]')
.type('testpassword')
.get("[type='submit']")
.click();
} else {
cy.get("[type='submit']").click();
}
})

The problem with conditional testing is that it can only be used when the state has stabilized. In modern day applications, knowing when state is stable is oftentimes impossible.

This problem applies to me, as it takes time for the request to validate the email to resolve, and Cypress might have already taken the wrong path by then.
On the other hand, waiting for XHR is not very robust either as I do not have control over when the validating request is to be returned.
I settled on waiting for 1s for now in this specific scenario. On other scenarios I seek to see if I could wait for the XHR to resolve instead of hard coding the waiting time.