Skip to content

armgit / mocha

Public Imported from GitHub
0

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

normalize getters and setters (fixes #3058)

Christian2303c669ef1b
diff --git a/lib/context.js b/lib/context.js
index 073643b8..f5a80118 100644
--- a/lib/context.js
+++ b/lib/context.js
@@ -29,7 +29,7 @@ Context.prototype.runnable = function (runnable) {
};
/**
- * Set test timeout `ms`.
+ * Set or get test timeout `ms`.
*
* @api private
* @param {number} ms
@@ -51,18 +51,24 @@ Context.prototype.timeout = function (ms) {
* @return {Context} self
*/
Context.prototype.enableTimeouts = function (enabled) {
+ if (!arguments.length) {
+ return this.runnable().enableTimeouts();
+ }
this.runnable().enableTimeouts(enabled);
return this;
};
/**
- * Set test slowness threshold `ms`.
+ * Set or get test slowness threshold `ms`.
*
* @api private
* @param {number} ms
* @return {Context} self
*/
Context.prototype.slow = function (ms) {
+ if (!arguments.length) {
+ return this.runnable().slow();
+ }
this.runnable().slow(ms);
return this;
};
@@ -78,7 +84,7 @@ Context.prototype.skip = function () {
};
/**
- * Allow a number of retries on failed tests
+ * Set or get a number of allowed retries on failed tests
*
* @api private
* @param {number} n
diff --git a/lib/runnable.js b/lib/runnable.js
index 946f2783..694d4f59 100644
--- a/lib/runnable.js
+++ b/lib/runnable.js
@@ -91,14 +91,14 @@ Runnable.prototype.timeout = function (ms) {
};
/**
- * Set & get slow `ms`.
+ * Set or get slow `ms`.
*
* @api private
* @param {number|string} ms
* @return {Runnable|number} ms or Runnable instance.
*/
Runnable.prototype.slow = function (ms) {
- if (typeof ms === 'undefined') {
+ if (!arguments.length || typeof ms === 'undefined') {
return this._slow;
}
if (typeof ms === 'string') {
@@ -144,7 +144,7 @@ Runnable.prototype.isPending = function () {
};
/**
- * Set number of retries.
+ * Set or get number of retries.
*
* @api private
*/
@@ -156,7 +156,7 @@ Runnable.prototype.retries = function (n) {
};
/**
- * Get current retry
+ * Set or get current retry
*
* @api private
*/
@@ -242,7 +242,7 @@ Runnable.prototype.resetTimeout = function () {
};
/**
- * Whitelist a list of globals for this test run.
+ * Set or get a list of whitelisted globals for this test run.
*
* @api private
* @param {string[]} globals
diff --git a/lib/suite.js b/lib/suite.js
index f5dca4cf..bb103dba 100644
--- a/lib/suite.js
+++ b/lib/suite.js
@@ -92,7 +92,7 @@ Suite.prototype.clone = function () {
};
/**
- * Set timeout `ms` or short-hand such as "2s".
+ * Set or get timeout `ms` or short-hand such as "2s".
*
* @api private
* @param {number|string} ms
@@ -114,7 +114,7 @@ Suite.prototype.timeout = function (ms) {
};
/**
- * Set number of times to retry a failed test.
+ * Set or get number of times to retry a failed test.
*
* @api private
* @param {number|string} n
@@ -130,7 +130,7 @@ Suite.prototype.retries = function (n) {
};
/**
- * Set timeout to `enabled`.
+ * Set or get timeout to `enabled`.
*
* @api private
* @param {boolean} enabled
@@ -146,7 +146,7 @@ Suite.prototype.enableTimeouts = function (enabled) {
};
/**
- * Set slow `ms` or short-hand such as "2s".
+ * Set or get slow `ms` or short-hand such as "2s".
*
* @api private
* @param {number|string} ms
@@ -165,7 +165,7 @@ Suite.prototype.slow = function (ms) {
};
/**
- * Sets whether to bail after first error.
+ * Set or get whether to bail after first error.
*
* @api private
* @param {boolean} bail
diff --git a/test/unit/context.spec.js b/test/unit/context.spec.js
index 75a85f6c..67033244 100644
--- a/test/unit/context.spec.js
+++ b/test/unit/context.spec.js
@@ -73,6 +73,18 @@ describe('methods', function () {
});
});
+ describe('slow()', function () {
+ it('should return the slow', function () {
+ expect(this.slow()).to.equal(75);
+ });
+ });
+
+ describe('enableTimeouts()', function () {
+ it('should return the enableTimeouts', function () {
+ expect(this.enableTimeouts()).to.equal(true);
+ });
+ });
+
describe('retries', function () {
it('should return the number of retries', function () {
expect(this.retries()).to.equal(-1);