-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
iterateJsdoc.js
85 lines (83 loc) · 2.46 KB
/
iterateJsdoc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* eslint-disable max-nested-callbacks */
import {
expect,
} from 'chai';
import {
// eslint-disable-next-line import/no-named-default
parseComment, default as iterateJsdoc,
} from '../src/iterateJsdoc';
describe('iterateJsdoc', () => {
describe('constructor', () => {
context('options', () => {
it('throws with missing options', () => {
expect(() => {
iterateJsdoc(() => {});
}).to.throw(TypeError);
});
});
context('meta', () => {
context('Invalid arguments', () => {
context('Invalid iterator', () => {
it('throws with missing function', () => {
expect(() => {
iterateJsdoc(undefined, {meta: {type: 'suggestion'}});
}).to.throw(TypeError);
});
it('throws with object missing `returns` method', () => {
expect(() => {
iterateJsdoc({}, {meta: {type: 'suggestion'}});
}).to.throw(TypeError);
});
});
context('Invalid options', () => {
it('throws with missing meta', () => {
expect(() => {
iterateJsdoc(() => {}, {});
}).to.throw(TypeError);
});
it('throws with empty meta', () => {
expect(() => {
iterateJsdoc(() => {}, {meta: {}});
}).to.throw(TypeError);
});
it('throws with bad type', () => {
expect(() => {
iterateJsdoc(() => {}, {meta: {type: 'bad'}});
}).to.throw(TypeError);
});
});
});
context('Valid arguments', () => {
it('Does not throw with function and options', () => {
expect(() => {
iterateJsdoc(() => {}, {meta: {type: 'suggestion'}});
}).to.not.throw();
});
});
});
});
describe('parseComment', () => {
context('Parses comments', () => {
it('', () => {
expect(parseComment({value: `* SomeDescription
@param {MyType} name desc
`}, '')).to.deep.equal({
description: 'SomeDescription',
line: 0,
source: 'SomeDescription\n@param {MyType} name desc',
tags: [
{
description: 'desc',
line: 1,
name: 'name',
optional: false,
source: '@param {MyType} name desc',
tag: 'param',
type: 'MyType',
},
],
});
});
});
});
});