Skip to content

armgit / mocha

Public Imported from GitHub
0

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

fix `this.timeout("5s")` support

TJ Holowaychuka487ea4ad5b6
diff --git a/lib/runnable.js b/lib/runnable.js
index 2c1faa79..087f94e0 100644
--- a/lib/runnable.js
+++ b/lib/runnable.js
@@ -4,7 +4,8 @@
*/
var EventEmitter = require('events').EventEmitter
- , debug = require('debug')('mocha:runnable');
+ , debug = require('debug')('mocha:runnable')
+ , milliseconds = require('./ms');
/**
* Save timer references to avoid Sinon interfering (see GH-237).
@@ -49,13 +50,14 @@ Runnable.prototype.__proto__ = EventEmitter.prototype;
/**
* Set & get timeout `ms`.
*
- * @param {Number} ms
+ * @param {Number|String} ms
* @return {Runnable|Number} ms or self
* @api private
*/
Runnable.prototype.timeout = function(ms){
if (0 == arguments.length) return this._timeout;
+ if ('string' == typeof ms) ms = milliseconds(ms);
debug('timeout %d', ms);
this._timeout = ms;
if (this.timer) this.resetTimeout();
@@ -65,13 +67,14 @@ Runnable.prototype.timeout = function(ms){
/**
* Set & get slow `ms`.
*
- * @param {Number} ms
+ * @param {Number|String} ms
* @return {Runnable|Number} ms or self
* @api private
*/
Runnable.prototype.slow = function(ms){
if (0 === arguments.length) return this._slow;
+ if ('string' == typeof ms) ms = milliseconds(ms);
debug('timeout %d', ms);
this._slow = ms;
return this;