Mocha: Add a hook to fail current test

Created on 16 May 2017  路  1Comment  路  Source: mochajs/mocha

We would like to enforce that our tests are not emitting any warnings. We have some 3rd party modules that console.error warnings, which we can overload in our mocha --require bootstrap.js file, but unfortunately some modules catch any errors we throw, so they never bubble back up to our unit test. It would nice if Mocha exposed some hook where we could just call Mocha.fail(message || error)

Most helpful comment

I recently discovered on stackOverflow the existence of this.test.error() is exposed in afterEach, there looks to be no documentation about this on the mocha website and it pretty hard to find if you don't know what to search for. Consider adding some documentation. That is sufficient for my usecase, so I'm going to close this. Thanks!

>All comments

I recently discovered on stackOverflow the existence of this.test.error() is exposed in afterEach, there looks to be no documentation about this on the mocha website and it pretty hard to find if you don't know what to search for. Consider adding some documentation. That is sufficient for my usecase, so I'm going to close this. Thanks!

Was this page helpful?
0 / 5 - 0 ratings