Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Fixed uncaught exceptions in hooks

Tj Holowaychuk364a0ad6c04e
diff --git a/lib/runner.js b/lib/runner.js
index 68c669f5..9f7db06a 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -149,7 +149,7 @@ Runner.prototype.hook = function(name, fn){
, timer;
function next(i) {
- var hook = hooks[i];
+ var hook = self.currentRunnable = hooks[i];
if (!hook) return fn();
self.emit('hook', hook);
@@ -306,7 +306,7 @@ Runner.prototype.runTests = function(suite, fn){
}
// execute test and hook(s)
- self.emit('test', self.test = test);
+ self.emit('test', self.test = self.currentRunnable = test);
self.hookDown('beforeEach', function(){
self.runTest(function(err){
if (err) return next(err);
@@ -381,7 +381,7 @@ Runner.prototype.run = function(fn){
// uncaught exception
function uncaught(err){
- self.fail(self.test, err);
+ self.fail(self.currentRunnable, err);
self.emit('test end', self.test);
self.emit('end');
}