cypress-io/eslint-plugin-cypress

Enforce Cypress listener rules

Aperta

#321 aperta il 3 apr 2026

 (1 commento) (0 reazioni) (0 assegnatari)JavaScript (95 fork)auto 404
good first issue

Metriche repository

Star
 (728 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

Problems

  1. I noticed in a project that there was a Cypress.on listener defined in a beforeEach, yet no Cypress.off to remove it, so the listener is added each time the beforeEach runs.

cy.on listeners are cleaned up before tests, but Cypress.on need to be unregistered when they're no longer needed.

beforeEach(function () {
  Cypress.on('uncaught:exception', (err, runnable) => {
    return false
  })
})
  1. I also saw a case where a Cypress.on listener was defined in a test, where it was assumed it was scoped to that single test, but it was applying throughout the session. So other tests where the listener was not intended to suppress the uncaught:exception events were being mistakenly suppressed (potentially not catching bugs)

  2. Cypress commands don't execute within Cypress.on listeners and there should be an error when people try to do this because it does nothing. https://github.com/cypress-io/cypress/issues/6316

What's needed

Suggest creating some eslint rules to enforce good Cypress listener rules to address these.

Guida contributor