☕️ Classic, reliable, trusted test framework for Node.js and the browser
Add promise support (close #329, close #1036)
Travis Jefferya2968bf64e13
diff --git a/lib/runnable.js b/lib/runnable.jsindex 03b8792b..42e5c4c7 100644--- a/lib/runnable.js+++ b/lib/runnable.js@@ -170,12 +170,12 @@ Runnable.prototype.run = function(fn){// timeoutif (this.async) {- if (ms) {- this.timer = setTimeout(function(){+ this.timer = setTimeout(function(){+ if (!finished) {done(new Error('timeout of ' + ms + 'ms exceeded'));self.timedOut = true;- }, ms);- }+ }+ }, ms);}// called multiple times@@ -218,10 +218,22 @@ Runnable.prototype.run = function(fn){// synctry {- if (!this.pending) this.fn.call(ctx);- this.duration = new Date - start;- fn();+ if (!this.pending) {+ var result = this.fn.call(ctx);+ if (result && typeof result.then === 'function') {+ result.then(+ function(){+ done();+ },+ done+ );+ } else {+ done();+ }+ } else {+ done();+ }} catch (err) {- fn(err);+ done(err);}};