Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Fix: Bail flag causes before() hooks to be run even after a failure

Aaron Krause552813282d88
diff --git a/lib/runner.js b/lib/runner.js
index 968e4080..81caa7fa 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -569,7 +569,7 @@ Runner.prototype.runSuite = function(suite, fn) {
debug('run suite %s', suite.fullTitle());
- if (!total) {
+ if (!total || (self.failures && suite._bail)) {
return fn();
}
diff --git a/test/integration/fixtures/options/bail.js b/test/integration/fixtures/options/bail.js
index bb8ad13d..32d17e9a 100644
--- a/test/integration/fixtures/options/bail.js
+++ b/test/integration/fixtures/options/bail.js
@@ -11,13 +11,9 @@ describe('suite1', function() {
});
describe('suite2', function() {
- // TODO: When uncommented, the hook below is ran and throws an exception
- // despite the previous failure with the bail flag. This is a bug. Uncomment
- // once resolved
-
- // before(function(done) {
- // throw new Error('this hook should not be displayed');
- // });
+ before(function(done) {
+ throw new Error('this hook should not be displayed');
+ });
it('should not display this error', function(done) {
throw new Error('this should not be displayed');