# Assertions

Examples of asserting the state or behavior of your application in Cypress, for a full reference of commands, go to docs.cypress.io

### Implicit Assertions

#### cy.should()

To make an assertion about the current subject, use the `cy.should()` command.

    cy
      .get('.assertion-table')
        .find('tbody tr:last').should('have.class', 'success')

# | Column heading | Column heading
--- | --- | ---
1 | Column content | Column content
2 | Column content | Column content
3 | Column content | Column content

#### cy.and()

To chain multiple assertions together, use the `cy.and()` command.

    cy
      .get('.assertions-link')
        .should('have.class', 'active')
        .and('have.attr', 'href')
        .and('include', 'cypress.io')

Cypress Docs

### Explicit Assertions

#### expect

To make an assertion about a specified subject, use `expect`.

    // We can use Chai's BDD style assertions
    expect(true).to.be.true

    // Pass a function to should that can have any number
    // of explicit assertions within it.
    cy
      .get('.assertions-p').find('p')
      .should(function($p){
        // return an array of texts from all of the p's
        var texts = $p.map(function(i, el){
          // https://on.cypress.io/api/cypress-jquery
          return Cypress.$(el).text()
        })

        // jquery map returns jquery object
        // and .get() convert this to simple array
        var texts = texts.get()

        // array should have length of 3
        expect(texts).to.have.length(3)

        // set this specific subject
        expect(texts).to.deep.eq([
          'Some text from first p',
          'More text from second p',
          'And even more text from third p'
        ])
    })

Some text from first p

More text from second p

And even more text from third p