Skip to content

Commit f70bb78

Browse files
committed
offering to the coverage gods
1 parent 8eb52d8 commit f70bb78

File tree

3 files changed

+77
-15
lines changed

3 files changed

+77
-15
lines changed

lib/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ exports.isString = function(obj) {
6363
exports.slug = function(str) {
6464
return str
6565
.toLowerCase()
66-
.replace(/ +/g, '-')
67-
.replace(/[^-\w]/g, '');
66+
.replace(/\s+/g, '-')
67+
.replace(/[^-\w]/g, '')
68+
.replace(/-{2,}/g, '-');
6869
};
6970

7071
/**

test/unit/mocha.spec.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ describe('Mocha', function() {
1717
});
1818

1919
describe('constructor', function() {
20+
var mocha;
21+
2022
beforeEach(function() {
23+
mocha = sandbox.createStubInstance(Mocha);
24+
mocha.timeout.returnsThis();
25+
mocha.retries.returnsThis();
2126
sandbox.stub(Mocha.prototype, 'timeout').returnsThis();
2227
sandbox.stub(Mocha.prototype, 'global').returnsThis();
28+
sandbox.stub(Mocha.prototype, 'retries').returnsThis();
29+
sandbox.stub(Mocha.prototype, 'rootHooks').returnsThis();
2330
});
2431

2532
it('should set _cleanReferencesAfterRun to true', function() {
@@ -34,8 +41,8 @@ describe('Mocha', function() {
3441
});
3542
});
3643

37-
describe('when "options.timeout" is `false`', function() {
38-
it('should set a timeout of 0', function() {
44+
describe('when `timeout` option is `false`', function() {
45+
it('should attempt to set timeout', function() {
3946
// eslint-disable-next-line no-new
4047
new Mocha({timeout: false});
4148
expect(Mocha.prototype.timeout, 'to have a call satisfying', [0]).and(
@@ -44,15 +51,43 @@ describe('Mocha', function() {
4451
});
4552
});
4653

47-
describe('when "options.global" is provided', function() {
48-
it('should pass "options.global" to #global()', function() {
54+
describe('when `global` option is an `Array`', function() {
55+
it('should attempt to set globals', function() {
4956
// eslint-disable-next-line no-new
5057
new Mocha({global: ['singular']});
5158
expect(Mocha.prototype.global, 'to have a call satisfying', [
5259
['singular']
5360
]).and('was called once');
5461
});
5562
});
63+
64+
describe('when `retries` option is present', function() {
65+
it('should attempt to set retries`', function() {
66+
// eslint-disable-next-line no-new
67+
new Mocha({retries: 1});
68+
expect(Mocha.prototype.retries, 'to have a call satisfying', [1]).and(
69+
'was called once'
70+
);
71+
});
72+
});
73+
74+
describe('when `retries` option is not present', function() {
75+
it('should not attempt to set retries', function() {
76+
// eslint-disable-next-line no-new
77+
new Mocha({});
78+
expect(Mocha.prototype.retries, 'was not called');
79+
});
80+
});
81+
82+
describe('when `rootHooks` option is truthy', function() {
83+
it('shouid attempt to set root hooks', function() {
84+
// eslint-disable-next-line no-new
85+
new Mocha({rootHooks: ['a root hook']});
86+
expect(Mocha.prototype.rootHooks, 'to have a call satisfying', [
87+
['a root hook']
88+
]).and('was called once');
89+
});
90+
});
5691
});
5792

5893
describe('#allowUncaught()', function() {

test/unit/utils.spec.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('lib/utils', function() {
1414
sandbox.restore();
1515
});
1616

17-
describe('clean', function() {
17+
describe('clean()', function() {
1818
it('should remove the wrapping function declaration', function() {
1919
expect(
2020
utils.clean('function (one, two, three) {\n//code\n}'),
@@ -149,7 +149,7 @@ describe('lib/utils', function() {
149149
});
150150
});
151151

152-
describe('stringify', function() {
152+
describe('stringify()', function() {
153153
var stringify = utils.stringify;
154154

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

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

531531
var type = utils.type;
@@ -588,7 +588,7 @@ describe('lib/utils', function() {
588588
});
589589
});
590590

591-
describe('isPromise', function() {
591+
describe('isPromise()', function() {
592592
it('should return true if the value is Promise-ish', function() {
593593
expect(
594594
utils.isPromise({
@@ -612,7 +612,7 @@ describe('lib/utils', function() {
612612
});
613613
});
614614

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

637-
describe('deprecate', function() {
637+
describe('deprecate()', function() {
638638
var emitWarning;
639639

640640
beforeEach(function() {
@@ -674,7 +674,7 @@ describe('lib/utils', function() {
674674
});
675675
});
676676

677-
describe('warn', function() {
677+
describe('warn()', function() {
678678
var emitWarning;
679679

680680
beforeEach(function() {
@@ -710,21 +710,25 @@ describe('lib/utils', function() {
710710
});
711711
});
712712

713-
describe('sQuote/dQuote', function() {
713+
describe('sQuote()', function() {
714714
var str = 'xxx';
715715

716716
it('should return its input as string wrapped in single quotes', function() {
717717
var expected = "'xxx'";
718718
expect(utils.sQuote(str), 'to be', expected);
719719
});
720+
});
721+
722+
describe('dQuote()', function() {
723+
var str = 'xxx';
720724

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

727-
describe('createMap', function() {
731+
describe('createMap()', function() {
728732
it('should return an object with a null prototype', function() {
729733
expect(Object.getPrototypeOf(utils.createMap()), 'to be', null);
730734
});
@@ -743,4 +747,26 @@ describe('lib/utils', function() {
743747
);
744748
});
745749
});
750+
751+
describe('slug()', function() {
752+
it('should convert the string to lowercase', function() {
753+
expect(utils.slug('FOO'), 'to be', 'foo');
754+
});
755+
756+
it('should convert whitespace to dashes', function() {
757+
expect(
758+
utils.slug('peanut butter\nand\tjelly'),
759+
'to be',
760+
'peanut-butter-and-jelly'
761+
);
762+
});
763+
764+
it('should strip non-alphanumeric and non-dash characters', function() {
765+
expect(utils.slug('murder-hornets!!'), 'to be', 'murder-hornets');
766+
});
767+
768+
it('should disallow consecutive dashes', function() {
769+
expect(utils.slug('poppies & fritz'), 'to be', 'poppies-fritz');
770+
});
771+
});
746772
});

0 commit comments

Comments
 (0)