Skip to content

Latest commit

 

History

History

blogs__assertion-counting

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Assertion counting

Read the blog post When can the test stop?

See the application in index.html that shows window.confirm on click

Window confirm

The cypress/e2e/spec.cy.js shows various ways the tests can ensure the async assertions finish before the test finishes. The last test shows how to use cypress-expect-n-assertions to automatically wait for declared number of assertions to run before finishing the test.

import { plan } from 'cypress-expect-n-assertions'
it('waits for planned number of assertion to run', () => {
  plan(1)
  cy.visit('index.html')

  cy.on('window:confirm', (message) => {
    expect(message).to.equal('Are you sure?')
  })

  cy.get('#click').click()
})

Automatic waiting for expected number of assertions to run

Unhandled promise rejections

If the application code creates an unhandled rejected promise, Cypress does NOT see it by default. If you want to fail the test, listen to the unhandled promise event and throw an error. See spec file errors.cy.js

Fail the test when a promise is rejected and is not handled