Sha256: bc3a70937a38266a4dd03ac0bcf6c4793855f164ab4ea2fc5a1dfb7a9781dfe6

Contents?: true

Size: 1.79 KB

Versions: 20

Compression:

Stored size: 1.79 KB

Contents

/// <reference types="Cypress" />

context('Assertions', () => {
  beforeEach(() => {
    cy.visit('https://example.cypress.io/commands/assertions')
  })

  describe('Implicit Assertions', () => {

    it('.should() - make an assertion about the current subject', () => {
      // https://on.cypress.io/should
      cy.get('.assertion-table')
        .find('tbody tr:last').should('have.class', 'success')
    })

    it('.and() - chain multiple assertions together', () => {
      // https://on.cypress.io/and
      cy.get('.assertions-link')
        .should('have.class', 'active')
        .and('have.attr', 'href')
        .and('include', 'cypress.io')
    })
  })

  describe('Explicit Assertions', () => {
    // https://on.cypress.io/assertions
    it('expect - make an assertion about a specified subject', () => {
      // 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(($p) => {
        // return an array of texts from all of the p's
        let texts = $p.map((i, el) => // https://on.cypress.io/$
          Cypress.$(el).text())

        // jquery map returns jquery object
        // and .get() convert this to simple array
        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',
        ])
      })
    })

    it('assert - assert shape of an object', () => {
      const person = {
        name: 'Joe',
        age: 20,
      }
      assert.isObject(person, 'value is object')
    })
  })
})

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
cypress-on-rails-1.12.1 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.12.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.11.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.10.1 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.9.1 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.9.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.8.1 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.8.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.7.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.6.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.5.1 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.5.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.4.2 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.4.1 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.4.0 lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.3.0 lib/generators/cypress_dev/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.2.1 lib/generators/cypress_dev/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.2.0 lib/generators/cypress_dev/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.1.1 lib/generators/cypress_dev/templates/spec/cypress/integration/examples/assertions.spec.js
cypress-on-rails-1.1.0 lib/generators/cypress_dev/templates/spec/cypress/integration/examples/assertions.spec.js