Skip to content

Commit 9ef4bcb

Browse files
author
Alexej Yaroshevich
committed
split param tests to separated files (for simplicity)
- add basic tests for configuring with empty data - add configure and check helpers to tester - change mocha reporter to dot
1 parent 5c963e0 commit 9ef4bcb

8 files changed

Lines changed: 216 additions & 218 deletions

File tree

test/init.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ function rulesChecker(opts) {
5050
checker.configure({jsDoc: rules});
5151
});
5252
},
53+
configure: function(rules) {
54+
checker.configure({jsDoc: rules});
55+
},
5356
cases: function(items) {
5457
items = items || [];
5558
items.forEach(function(test) {
@@ -82,6 +85,9 @@ function rulesChecker(opts) {
8285
});
8386

8487
});
88+
},
89+
check: function(str) {
90+
return checker.checkString(str);
8591
}
8692
};
8793
}

test/lib/rules/validate-jsdoc.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
1+
var assert = require('assert');
2+
13
describe('rules/validate-jsdoc', function () {
24
var checker = global.checker({
35
additionalRules: ['lib/rules/validate-jsdoc.js']
46
});
57

6-
describe('basic checks', function () {
8+
describe('configure', function () {
9+
10+
it('should throw on call without params', function () {
11+
assert.throws(function () {
12+
checker.configure();
13+
});
14+
});
15+
16+
it('should throw with true', function () {
17+
assert.throws(function () {
18+
checker.configure(true);
19+
});
20+
});
21+
22+
it('should throw with empty object', function () {
23+
assert.throws(function () {
24+
checker.configure({});
25+
});
26+
});
727

8-
checker.rules({checkReturnTypes: true});
9-
checker.cases([
10-
/* jshint ignore:start */
11-
{
12-
it: 'shouldn\'t throw',
13-
errors: 1,
14-
code: function () {
15-
/**
16-
* @return {Foo}
17-
*/
18-
function getFoo() {
19-
return new Bar();
20-
}
21-
}
22-
}
23-
/* jshint ignore:end */
24-
]);
28+
it('should throw with unknown key', function () {
29+
assert.throws(function () {
30+
checker.configure({unknownRule: true});
31+
});
32+
});
2533

2634
});
2735
});

test/lib/rules/validate-jsdoc/check-param-names.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
describe('rules/validate-jsdoc @param', function () {
1+
describe('rules/validate-jsdoc', function () {
22
var checker = global.checker({
33
additionalRules: ['lib/rules/validate-jsdoc.js']
44
});
55
checker.rules({checkParamNames: true});
66

7-
describe('common', function () {
7+
describe('check-param-names', function () {
88

99
checker.cases([
1010
/* jshint ignore:start */
@@ -19,17 +19,7 @@ describe('rules/validate-jsdoc @param', function () {
1919
}
2020
},
2121
errors: 1
22-
}
23-
/* jshint ignore:end */
24-
]);
25-
26-
});
27-
28-
describe('param-names', function () {
29-
30-
checker.cases([
31-
/* jshint ignore:start */
32-
{
22+
}, {
3323
it: 'should report error in jsdoc for function',
3424
code: function () {
3525
var x = 1;
@@ -77,10 +67,7 @@ describe('rules/validate-jsdoc @param', function () {
7767
/* jshint ignore:end */
7868
]);
7969

80-
});
81-
82-
describe('param-names location', function () {
83-
70+
// locations
8471
checker.cases([
8572
/* jshint ignore:start */
8673
{
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
describe('rules/validate-jsdoc', function () {
2+
var checker = global.checker({
3+
additionalRules: ['lib/rules/validate-jsdoc.js']
4+
});
5+
6+
describe('check-redundant-params', function () {
7+
checker.rules({checkRedundantParams: true});
8+
9+
checker.cases([
10+
/* jshint ignore:start */
11+
{
12+
it: 'should report redundant jsdoc-param for function',
13+
errors: 1,
14+
code: function () {
15+
var x = 1;
16+
/**
17+
* @param {String} yyy
18+
*/
19+
function funcName() {
20+
// dummy
21+
}
22+
}
23+
}, {
24+
it: 'should report redundant jsdoc-param for method',
25+
errors: 1,
26+
code: function () {
27+
Cls.prototype = {
28+
/**
29+
* @param {String} yyy
30+
*/
31+
run: function () {
32+
// dummy
33+
}
34+
};
35+
}
36+
}, {
37+
it: 'should not report redundant jsdoc-param for function',
38+
code: function () {
39+
/**
40+
* @param {Object} [elem] Nested element
41+
* @param {String} [modName1, ..., modNameN] Modifier names
42+
*/
43+
function funcName(elem) {
44+
// dummy
45+
}
46+
}
47+
}, {
48+
it: 'should not report valid jsdoc for method',
49+
code: function () {
50+
var x = 1;
51+
/**
52+
* @param {String} xxx
53+
*/
54+
function funcName(xxx) {
55+
// dummy
56+
}
57+
}
58+
}, {
59+
it: 'should not report valid jsdoc for function',
60+
code: function () {
61+
Cls.prototype = {
62+
/**
63+
* @param {String} xxx
64+
*/
65+
run: function(xxx) {
66+
// dummy
67+
}
68+
};
69+
}
70+
}
71+
/* jshint ignore:end */
72+
]);
73+
74+
});
75+
76+
});

test/lib/rules/validate-jsdoc/check-return-types.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ describe('rules/validate-jsdoc', function () {
99
checker.cases([
1010
/* jshint ignore:start */
1111
{
12+
it: 'shouldn\'t throw',
13+
errors: 1,
14+
code: function () {
15+
/**
16+
* @return {Foo}
17+
*/
18+
function getFoo() {
19+
return new Bar();
20+
}
21+
}
22+
}, {
1223
it: 'should neither throw nor report',
1324
code: function () {
1425
/**
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
describe('rules/validate-jsdoc', function () {
2+
var checker = global.checker({
3+
additionalRules: ['lib/rules/validate-jsdoc.js']
4+
});
5+
6+
describe('require-param-types', function () {
7+
checker.rules({requireParamTypes: true});
8+
9+
checker.cases([
10+
/* jshint ignore:start */
11+
{
12+
it: 'should report missing jsdoc-param type for function',
13+
errors: 1,
14+
code: function () {
15+
var x = 1;
16+
/**
17+
* @param xxx
18+
*/
19+
function funcName(xxx) {
20+
// dummy
21+
}
22+
}
23+
}, {
24+
it: 'should report missing jsdoc-param type for method',
25+
errors: 1,
26+
code: function () {
27+
Cls.prototype = {
28+
/**
29+
* @param yyy
30+
*/
31+
run: function(xxx) {
32+
// dummy
33+
}
34+
};
35+
}
36+
}, {
37+
it: 'should not report valid jsdoc for method',
38+
code: function () {
39+
var x = 1;
40+
/**
41+
* @param {String} xxx
42+
*/
43+
function funcName(xxx) {
44+
// dummy
45+
}
46+
}
47+
}, {
48+
it: 'should not report valid jsdoc for function',
49+
code: function () {
50+
Cls.prototype = {
51+
/**
52+
* @param {String} xxx
53+
*/
54+
run: function(xxx) {
55+
// dummy
56+
}
57+
};
58+
}
59+
}, {
60+
it: 'should not report valid jsdoc with object type for method',
61+
code: function () {
62+
var x = 1;
63+
/**
64+
* @param {{foo: string}} xxx
65+
*/
66+
function funcName(xxx) {
67+
// dummy
68+
}
69+
}
70+
}, {
71+
it: 'should not report valid jsdoc with object type for function',
72+
code: function () {
73+
Cls.prototype = {
74+
/**
75+
* @param {{foo: string}} xxx
76+
*/
77+
run: function(xxx) {
78+
// dummy
79+
}
80+
};
81+
}
82+
}
83+
/* jshint ignore:end */
84+
]);
85+
86+
});
87+
88+
});

test/mocha.opts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
--recursive -u bdd -R spec
1+
test/*test*.js test/lib/
2+
--recursive
3+
--require test/init.js
4+
-R dot
5+
-u bdd

0 commit comments

Comments
 (0)