Cypress: Adding logic to the `fail` event per documentation negates test failure

Created on 27 Sep 2018  路  3Comments  路  Source: cypress-io/cypress

Is this a Feature or Bug?

Bug

Current behavior:

Documented code for Debugging when a test fails does not leave the test as a failure.
Referenced documentation https://docs.cypress.io/api/events/catalog-of-events.html#Catching-Test-Failures

Desired behavior:

Tests with failures still shown as failures in the log.

Steps to reproduce:

Add the following to support/index.js file:

Cypress.on('fail', (err, runnable) => {
  debugger
})

Create a test that fails and run it

Note: Adding runnable.emit('error', err); to the above event binding will have the error message show in log but does not mark the test as a failure.

Versions

OS: Windows 7
Browser: Chrome 66
Cypress: 3.1.0

Most helpful comment

I created a new issue in our docs to document how to fail a test after listening to 'fail' events here: https://github.com/cypress-io/cypress-documentation/issues/1045. Our documentation is open source and contributions are welcome. 馃槃

Since this seems to be a documentation issue and not an actual issue with Cypress's implementation, I will close this issue.

All 3 comments

Confirm, I had to adjust the code for the test to fail

Cypress.on("fail", (err, runnable) => {
  debugger
  return err
})

cc @scottcrowe

Also beware that if you use cypress-webpack-preprocessor, it's stripping debugger statements with default options

(spend more that little time debugging this)

https://github.com/cypress-io/cypress-webpack-preprocessor/issues/29

I created a new issue in our docs to document how to fail a test after listening to 'fail' events here: https://github.com/cypress-io/cypress-documentation/issues/1045. Our documentation is open source and contributions are welcome. 馃槃

Since this seems to be a documentation issue and not an actual issue with Cypress's implementation, I will close this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

igorpavlov picture igorpavlov  路  3Comments

zbigniewkalinowski picture zbigniewkalinowski  路  3Comments

carloscheddar picture carloscheddar  路  3Comments

szabyg picture szabyg  路  3Comments

Francismb picture Francismb  路  3Comments