From 2727c8f9f9197a4da4f929fbea7fbd43e72984e2 Mon Sep 17 00:00:00 2001 From: "Durand R. Van Arnem" Date: Thu, 10 Nov 2016 17:57:36 -0600 Subject: [PATCH] Fix the 'this' context that is passed to mocha functions to be compatible with Mocha's Shared Behaviors features: https://github.com/mochajs/mocha/wiki/Shared-Behaviours --- server.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 53f82bd0..e60e4c85 100755 --- a/server.js +++ b/server.js @@ -26,14 +26,15 @@ function setupGlobals(mocha) { //forking mocha itself. const wrappedFunction = function (done) { - var self = this._runnable; + var self = this; + var runnable = this._runnable; var run = function() { try { // Sync call if (fn.length == 0) { var result = fn.call(self); if (result && typeof result.then === 'function') { - self.resetTimeout(); + runnable.resetTimeout(); result .then(function() { done(); @@ -45,7 +46,7 @@ function setupGlobals(mocha) { done(reason || new Error('Promise rejected with no or falsy reason')); }); } else { - if (self.asyncOnly) { + if (runnable.asyncOnly) { return done(new Error('--async-only option in use without declaring `done()` or returning a promise')); }