4

When I try to start my mocha test with bail(false) I need to not stop tests even if some beforeEach hook gives an error.

But this doesn't help, did someobody coped with this earlier? Or.. is it possible?

Kosmetika
  • 20,774
  • 37
  • 108
  • 172

1 Answers1

0

In order for your tests to continue running even when the beforeEach() throws an error, you have to handle that error. Currently, beforeEach() is throwing an error which is unhandled.

To handle this error in NodeJS, use a callback with a parameter:

beforeEach(done) {
    // your code here

    // if there was an error
    if (error !== null) {
        // callback with a parameter, indicates failure
        done(new Error('failed'));
    } else {
        // more code here
        // callback without parameter, indicates success!
        done();
    }
}
nyarasha
  • 1,119
  • 1
  • 14
  • 24