Search⌘ K
AI Features

Assertions

Explore how to make effective assertions in Cypress testing by chaining should commands and using expect to validate UI elements. Understand stubs, clock control, and simulating server responses with routes and fixtures to write comprehensive JavaScript tests.

We'll cover the following...

After you’ve done all the actions, you’re likely going to make some assertions about what’s on the page. Cypress assertions are kind of complicated on one level in that there are a lot of options, but at the same time, the syntax has a couple of common patterns.

You can chain an assertion at the end of a series of commands with should. However, you need to do something between cy and should. You can’t just write cy.should("exist"), but you can write cy.get("selector").should("exist").

The should command typically takes as its first argument, what the Cypress docs call a chainer. Cypress takes its assertions from a library called Chai. Assertions in Chai are a chain of methods, as in to.be.null, or to.have.class or to.be.visible. A Cypress chainer is a string version of ...