Skip to content

Commit d3a05d0

Browse files
committed
start testing
1 parent 2a04b3b commit d3a05d0

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "helpers for building themes with documentation.js",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "tap --coverage test"
88
},
99
"keywords": [
1010
"documentation",
@@ -17,5 +17,9 @@
1717
"dependencies": {
1818
"doctrine": "^0.7.2",
1919
"globals-docs": "^2.1.0"
20+
},
21+
"devDependencies": {
22+
"mdast": "^2.3.0",
23+
"tap": "^2.3.1"
2024
}
2125
}

test/format_type.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*eslint max-len: 0 */
2+
'use strict';
3+
4+
var formatType = require('../index').formatType,
5+
mdast = require('mdast'),
6+
parseParamType = require('doctrine/lib/typed').parseParamType,
7+
test = require('tap').test;
8+
9+
test('formatType', function (t) {
10+
[
11+
['Foo', 'Foo'],
12+
['null', 'null'],
13+
['null', 'null'],
14+
['*', 'Any'],
15+
['Array|undefined', '([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)|[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined))'],
16+
['Array<number>', '[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array).&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)&gt;'],
17+
['number!', '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)!'],
18+
['function(string, boolean)', 'function ([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean))'],
19+
['function(string, boolean): number', 'function ([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)): [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)'],
20+
['function()', 'function ()'],
21+
['function(this:something, string)', 'function (this: something, [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))'],
22+
['function(new:something)', 'function (new: something)'],
23+
['{myNum: number, myObject}', '{myNum: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), myObject}'],
24+
['[string,]', '&#91;[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)&#93;'],
25+
['number?', '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?'],
26+
['?number', '?[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)'],
27+
['?', '?'],
28+
['void', 'void'],
29+
['function(a:b)', 'function (a: b)'],
30+
['function(a):void', 'function (a): void'],
31+
['number=', '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)='],
32+
['...number', '...[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)'],
33+
['undefined', '[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)']
34+
].forEach(function (example) {
35+
t.deepEqual(mdast().stringify({
36+
type: 'paragraph',
37+
children: formatType(parseParamType(example[0]))
38+
}), example[1], example[0]);
39+
});
40+
41+
t.deepEqual(formatType(), [], 'empty case');
42+
43+
t.throws(function () {
44+
formatType({});
45+
});
46+
47+
t.end();
48+
});

0 commit comments

Comments
 (0)