UNPKG

3.92 kBJavaScriptView Raw
1'use strict';
2
3describe('plugins/overloadHelper', function() {
4 var env = require('jsdoc/env');
5 var path = require('jsdoc/path');
6
7 var docSet;
8 var parser = jasmine.createParser();
9 var pluginPath = 'plugins/overloadHelper';
10 var pluginPathResolved = path.resolve(env.dirname, pluginPath);
11 var plugin = require(pluginPathResolved);
12
13 require('jsdoc/plugins').installPlugins([pluginPathResolved], parser);
14 docSet = jasmine.getDocSetFromFile('plugins/test/fixtures/overloadHelper.js', parser);
15
16 it('should exist', function() {
17 expect(plugin).toBeDefined();
18 expect(typeof plugin).toBe('object');
19 });
20
21 it('should export handlers', function() {
22 expect(plugin.handlers).toBeDefined();
23 expect(typeof plugin.handlers).toBe('object');
24 });
25
26 it('should export a "newDoclet" handler', function() {
27 expect(plugin.handlers.newDoclet).toBeDefined();
28 expect(typeof plugin.handlers.newDoclet).toBe('function');
29 });
30
31 it('should export a "parseComplete" handler', function() {
32 expect(plugin.handlers.parseComplete).toBeDefined();
33 expect(typeof plugin.handlers.parseComplete).toBe('function');
34 });
35
36 describe('newDoclet handler', function() {
37 it('should not add unique longnames to constructors', function() {
38 var soup = docSet.getByLongname('Soup');
39 var soup1 = docSet.getByLongname('Soup()');
40 var soup2 = docSet.getByLongname('Soup(spiciness)');
41
42 expect(soup.length).toBe(2);
43 expect(soup1.length).toBe(0);
44 expect(soup2.length).toBe(0);
45 });
46
47 it('should add unique longnames to methods', function() {
48 var slurp = docSet.getByLongname('Soup#slurp');
49 var slurp1 = docSet.getByLongname('Soup#slurp()');
50 var slurp2 = docSet.getByLongname('Soup#slurp(dBA)');
51
52 expect(slurp.length).toBe(0);
53 expect(slurp1.length).toBe(1);
54 expect(slurp2.length).toBe(1);
55 });
56
57 it('should update the "variation" property of the method', function() {
58 var slurp1 = docSet.getByLongname('Soup#slurp()')[0];
59 var slurp2 = docSet.getByLongname('Soup#slurp(dBA)')[0];
60
61 expect(slurp1.variation).toBe('');
62 expect(slurp2.variation).toBe('dBA');
63 });
64
65 it('should not add to or change existing variations that are unique', function() {
66 var salt1 = docSet.getByLongname('Soup#salt');
67 var salt2 = docSet.getByLongname('Soup#salt(mg)');
68
69 expect(salt1.length).toBe(1);
70 expect(salt2.length).toBe(1);
71 });
72
73 it('should not duplicate the names of existing numeric variations', function() {
74 var heat1 = docSet.getByLongname('Soup#heat(1)');
75 var heat2 = docSet.getByLongname('Soup#heat(2)');
76 var heat3 = docSet.getByLongname('Soup#heat(3)');
77
78 expect(heat1.length).toBe(1);
79 expect(heat2.length).toBe(1);
80 expect(heat3.length).toBe(1);
81 });
82
83 it('should replace identical variations with new, unique variations', function() {
84 var discard1 = docSet.getByLongname('Soup#discard()');
85 var discard2 = docSet.getByLongname('Soup#discard(container)');
86
87 expect(discard1.length).toBe(1);
88 expect(discard2.length).toBe(1);
89 });
90 });
91
92 describe('parseComplete handler', function() {
93 // disabled because on the second run, each comment is being parsed twice; who knows why...
94 xit('should not retain parse results between parser runs', function() {
95 parser.clear();
96 docSet = jasmine.getDocSetFromFile('plugins/test/fixtures/overloadHelper.js', parser);
97 var heat = docSet.getByLongname('Soup#heat(4)');
98
99 expect(heat.length).toBe(0);
100 });
101 });
102});