It's important to understand the mechanism Cypress uses to chain commands together. It manages a Promise chain on your behalf, with each command yielding a 'subject' to the following command until the chain ends or there is an error. The developer should not need to use Promises directly, but understanding how they work is helpful.
For example, a chain of Cypress commands looks like this:
cy.get(".todo-list li").find("label").should("contain", "Buy Milk")
However, it is important to note that not all Cypress commands yield a subject that can be chained. For instance, cy.clearCookies() yields
null, which cannot be chained.
When you want to act upon a subject directly from a Cypress command, you need to yield the subject to .then(). We cover .then() and cy.wrap() in the Understanding the Asynchronous nature of Cypress lesson.
You can learn more about command chaining from our docs here.