Skip to content

Commit

Permalink
normalize getters and setters (fixes mochajs#3058)
Browse files Browse the repository at this point in the history
  • Loading branch information
makepanic committed Oct 9, 2017
1 parent 9f204ba commit 8a12604
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
14 changes: 10 additions & 4 deletions lib/context.js
Expand Up @@ -29,7 +29,7 @@ Context.prototype.runnable = function (runnable) {
};

/**
* Set test timeout `ms`.
* Set or get test timeout `ms`.
*
* @api private
* @param {number} ms
Expand All @@ -44,25 +44,31 @@ Context.prototype.timeout = function (ms) {
};

/**
* Set test timeout `enabled`.
* Set or get test timeout `enabled`.
*
* @api private
* @param {boolean} enabled
* @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;
};
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/runnable.js
Expand Up @@ -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') {
Expand Down Expand Up @@ -144,7 +144,7 @@ Runnable.prototype.isPending = function () {
};

/**
* Set number of retries.
* Set or get number of retries.
*
* @api private
*/
Expand All @@ -156,7 +156,7 @@ Runnable.prototype.retries = function (n) {
};

/**
* Get current retry
* Set or get current retry
*
* @api private
*/
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/suite.js
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -130,7 +130,7 @@ Suite.prototype.retries = function (n) {
};

/**
* Set timeout to `enabled`.
* Set or get timeout to `enabled`.
*
* @api private
* @param {boolean} enabled
Expand All @@ -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
Expand All @@ -165,7 +165,7 @@ Suite.prototype.slow = function (ms) {
};

/**
* Sets whether to bail after first error.
* Sets or gets whether to bail after first error.
*
* @api private
* @param {boolean} bail
Expand Down
12 changes: 12 additions & 0 deletions test/unit/context.spec.js
Expand Up @@ -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);
Expand Down

0 comments on commit 8a12604

Please sign in to comment.