Repository metrics
- Stars
- (728 stars)
- PR merge metrics
- (PR metrics pending)
Description
Problems
- I noticed in a project that there was a
Cypress.onlistener defined in abeforeEach, yet noCypress.offto remove it, so the listener is added each time thebeforeEachruns.
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
})
})
-
I also saw a case where a
Cypress.onlistener 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) -
Cypress commands don't execute within
Cypress.onlisteners 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.