Skip to content

Commit

Permalink
offering to the coverage gods
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed May 14, 2020
1 parent 7050d59 commit 61d2389
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 15 deletions.
5 changes: 3 additions & 2 deletions lib/utils.js
Expand Up @@ -63,8 +63,9 @@ exports.isString = function(obj) {
exports.slug = function(str) {
return str
.toLowerCase()
.replace(/ +/g, '-')
.replace(/[^-\w]/g, '');
.replace(/\s+/g, '-')
.replace(/[^-\w]/g, '')
.replace(/-{2,}/g, '-');
};

/**
Expand Down
43 changes: 39 additions & 4 deletions test/unit/mocha.spec.js
Expand Up @@ -91,9 +91,16 @@ describe('Mocha', function() {
});

describe('constructor', function() {
var mocha;

beforeEach(function() {
mocha = sandbox.createStubInstance(Mocha);
mocha.timeout.returnsThis();
mocha.retries.returnsThis();
sandbox.stub(Mocha.prototype, 'timeout').returnsThis();
sandbox.stub(Mocha.prototype, 'global').returnsThis();
sandbox.stub(Mocha.prototype, 'retries').returnsThis();
sandbox.stub(Mocha.prototype, 'rootHooks').returnsThis();
});

it('should set _cleanReferencesAfterRun to true', function() {
Expand All @@ -108,8 +115,8 @@ describe('Mocha', function() {
});
});

describe('when `timeout` is `false`', function() {
it('should set a timeout of 0', function() {
describe('when `timeout` option is `false`', function() {
it('should attempt to set timeout', function() {
// eslint-disable-next-line no-new
new Mocha({timeout: false});
expect(Mocha.prototype.timeout, 'to have a call satisfying', [0]).and(
Expand All @@ -118,15 +125,43 @@ describe('Mocha', function() {
});
});

describe('when `global` option is provided', function() {
it('should configure `global` option', function() {
describe('when `global` option is an `Array`', function() {
it('should attempt to set globals', function() {
// eslint-disable-next-line no-new
new Mocha({global: ['singular']});
expect(Mocha.prototype.global, 'to have a call satisfying', [
['singular']
]).and('was called once');
});
});

describe('when `retries` option is present', function() {
it('should attempt to set retries`', function() {
// eslint-disable-next-line no-new
new Mocha({retries: 1});
expect(Mocha.prototype.retries, 'to have a call satisfying', [1]).and(
'was called once'
);
});
});

describe('when `retries` option is not present', function() {
it('should not attempt to set retries', function() {
// eslint-disable-next-line no-new
new Mocha({});
expect(Mocha.prototype.retries, 'was not called');
});
});

describe('when `rootHooks` option is truthy', function() {
it('shouid attempt to set root hooks', function() {
// eslint-disable-next-line no-new
new Mocha({rootHooks: ['a root hook']});
expect(Mocha.prototype.rootHooks, 'to have a call satisfying', [
['a root hook']
]).and('was called once');
});
});
});

describe('instance method', function() {
Expand Down
44 changes: 35 additions & 9 deletions test/unit/utils.spec.js
Expand Up @@ -14,7 +14,7 @@ describe('lib/utils', function() {
sandbox.restore();
});

describe('clean', function() {
describe('clean()', function() {
it('should remove the wrapping function declaration', function() {
expect(
utils.clean('function (one, two, three) {\n//code\n}'),
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('lib/utils', function() {
});
});

describe('stringify', function() {
describe('stringify()', function() {
var stringify = utils.stringify;

it('should return an object representation of a string created with a String constructor', function() {
Expand Down Expand Up @@ -525,7 +525,7 @@ describe('lib/utils', function() {
});
});

describe('type', function() {
describe('type()', function() {
/* eslint no-extend-native: off */

var type = utils.type;
Expand Down Expand Up @@ -588,7 +588,7 @@ describe('lib/utils', function() {
});
});

describe('isPromise', function() {
describe('isPromise()', function() {
it('should return true if the value is Promise-ish', function() {
expect(
utils.isPromise({
Expand All @@ -612,7 +612,7 @@ describe('lib/utils', function() {
});
});

describe('escape', function() {
describe('escape()', function() {
it('replaces the usual xml suspects', function() {
expect(utils.escape('<a<bc<d<'), 'to be', '&#x3C;a&#x3C;bc&#x3C;d&#x3C;');
expect(utils.escape('>a>bc>d>'), 'to be', '&#x3E;a&#x3E;bc&#x3E;d&#x3E;');
Expand All @@ -634,7 +634,7 @@ describe('lib/utils', function() {
});
});

describe('deprecate', function() {
describe('deprecate()', function() {
var emitWarning;

beforeEach(function() {
Expand Down Expand Up @@ -674,7 +674,7 @@ describe('lib/utils', function() {
});
});

describe('warn', function() {
describe('warn()', function() {
var emitWarning;

beforeEach(function() {
Expand Down Expand Up @@ -710,21 +710,25 @@ describe('lib/utils', function() {
});
});

describe('sQuote/dQuote', function() {
describe('sQuote()', function() {
var str = 'xxx';

it('should return its input as string wrapped in single quotes', function() {
var expected = "'xxx'";
expect(utils.sQuote(str), 'to be', expected);
});
});

describe('dQuote()', function() {
var str = 'xxx';

it('should return its input as string wrapped in double quotes', function() {
var expected = '"xxx"';
expect(utils.dQuote(str), 'to be', expected);
});
});

describe('createMap', function() {
describe('createMap()', function() {
it('should return an object with a null prototype', function() {
expect(Object.getPrototypeOf(utils.createMap()), 'to be', null);
});
Expand All @@ -743,4 +747,26 @@ describe('lib/utils', function() {
);
});
});

describe('slug()', function() {
it('should convert the string to lowercase', function() {
expect(utils.slug('FOO'), 'to be', 'foo');
});

it('should convert whitespace to dashes', function() {
expect(
utils.slug('peanut butter\nand\tjelly'),
'to be',
'peanut-butter-and-jelly'
);
});

it('should strip non-alphanumeric and non-dash characters', function() {
expect(utils.slug('murder-hornets!!'), 'to be', 'murder-hornets');
});

it('should disallow consecutive dashes', function() {
expect(utils.slug('poppies & fritz'), 'to be', 'poppies-fritz');
});
});
});

0 comments on commit 61d2389

Please sign in to comment.