Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Fixed: only emit "test end" for uncaught within test, not hook

TJ Holowaychuka14226f4e12e
diff --git a/lib/runner.js b/lib/runner.js
index 0ea294ae..e1d5c318 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -390,10 +390,11 @@ Runner.prototype.run = function(fn){
// uncaught exception
function uncaught(err){
+ var runnable = self.currentRunnable;
debug('uncaught exception');
- self.currentRunnable.clearTimeout();
- self.fail(self.currentRunnable, err);
- self.emit('test end', self.test);
+ runnable.clearTimeout();
+ self.fail(runnable, err);
+ if ('test' == runnable.type) self.emit('test end', runnable);
self.emit('end');
}
diff --git a/lib/test.js b/lib/test.js
index c910cc58..11773e0c 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -22,6 +22,7 @@ module.exports = Test;
function Test(title, fn) {
Runnable.call(this, title, fn);
this.pending = !fn;
+ this.type = 'test';
}
/**