Skip to content

Commit 7a1f033

Browse files
author
nfrasser
committed
Refactoring linkify-test tests for maintainability
- One assertion per example - beforeEach should set up each example uniquely - cleanup for each example in afterEach Will eventually refactor all tests in this fashion
1 parent c653bcb commit 7a1f033

File tree

1 file changed

+71
-44
lines changed

1 file changed

+71
-44
lines changed

test/spec/linkify-test.js

Lines changed: 71 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,60 +21,87 @@ var tokensTest = [
2121
];
2222

2323
describe('linkify', function () {
24-
it('Has all required methods and properties', function () {
25-
26-
// Functions
27-
linkify.tokenize.should.be.a('function');
28-
linkify.tokenize.length.should.be.eql(1);
29-
linkify.find.should.be.a('function');
30-
linkify.find.length.should.be.eql(1); // type is optional
31-
linkify.test.should.be.a('function');
32-
linkify.test.length.should.be.eql(1); // type is optional
33-
34-
// Properties
35-
linkify.options.should.be.a('object');
36-
linkify.parser.should.be.a('object');
37-
linkify.scanner.should.be.a('object');
3824

25+
describe('tokenize', function () {
26+
it('is a function', function () {
27+
linkify.tokenize.should.be.a('function');
28+
});
29+
it('takes a single argument', function () {
30+
linkify.tokenize.length.should.be.eql(1);
31+
});
3932
});
40-
});
4133

42-
describe('linkify.tokenize', function () {
43-
});
44-
45-
describe('linkify.find', function () {
34+
describe('find', function () {
35+
it('is a function', function () {
36+
linkify.find.should.be.a('function');
37+
});
38+
it('takes a single argument', function () {
39+
linkify.find.length.should.be.eql(1); // type is optional
40+
});
41+
});
4642

47-
});
43+
describe('test', function () {
44+
/*
45+
For each element,
4846
49-
describe('linkify.test', function () {
50-
/*
51-
For each element,
47+
* [0] is the input string
48+
* [1] is the expected return value
49+
* [2] (optional) the type of link to look for
50+
*/
51+
var tests = [
52+
['Herp derp', false],
53+
['Herp derp', false, 'email'],
54+
['Herp derp', false, 'asdf'],
55+
['https://google.com/?q=yey', true],
56+
['https://google.com/?q=yey', true, 'url'],
57+
['https://google.com/?q=yey', false, 'email'],
58+
['[email protected]', true],
59+
['[email protected]', false, 'url'],
60+
['[email protected]', true, 'email'],
61+
['t.co', true],
62+
['t.co g.co', false], // can only be one
63+
['[email protected] t.co', false] // can only be one
64+
];
5265

53-
* [0] is the input string
54-
* [1] is the expected return value
55-
* [2] (optional) the type of link to look for
56-
*/
57-
var tests = [
58-
['Herp derp', false],
59-
['Herp derp', false, 'email'],
60-
['Herp derp', false, 'asdf'],
61-
['https://google.com/?q=yey', true],
62-
['https://google.com/?q=yey', true, 'url'],
63-
['https://google.com/?q=yey', false, 'email'],
64-
['[email protected]', true],
65-
['[email protected]', false, 'url'],
66-
['[email protected]', true, 'email'],
67-
['t.co', true],
68-
['t.co g.co', false], // can only be one
69-
['[email protected] t.co', false] // can only be one
70-
];
66+
it('is a function', function () {
67+
linkify.test.should.be.a('function');
68+
});
69+
it('takes a single argument', function () {
70+
linkify.test.length.should.be.eql(1); // type is optional
71+
});
7172

72-
it('Correctly tests each example string', function () {
73-
var test;
73+
var test, testName;
74+
/* jshint loopfunc: true */
7475
for (var i = 0; i < tests.length; i++) {
7576
test = tests[i];
76-
linkify.test(test[0], test[2]).should.be.eql(test[1]);
77+
testName = 'Correctly tests the string "' + test[0] + '"';
78+
testName += ' as `' + (test[1] ? 'true' : 'false') + '`';
79+
if (test[2]) {
80+
testName += ' (' + test[2] + ')';
81+
}
82+
testName += '.';
83+
84+
it(testName, function () {
85+
linkify.test(test[0], test[2]).should.be.eql(test[1]);
86+
});
7787
}
7888
});
7989

90+
describe('options', function () {
91+
it('is an object', function () {
92+
linkify.options.should.be.a('object');
93+
});
94+
});
95+
96+
describe('parser', function () {
97+
it('is an object', function () {
98+
linkify.parser.should.be.a('object');
99+
});
100+
});
101+
102+
describe('scanner', function () {
103+
it('is an object', function () {
104+
linkify.scanner.should.be.a('object');
105+
});
106+
});
80107
});

0 commit comments

Comments
 (0)