|
| 1 | +describe('lib/rules/validate-jsdoc/require-param-description', function () { |
| 2 | + var checker = global.checker({ |
| 3 | + plugins: ['./lib/index'] |
| 4 | + }); |
| 5 | + |
| 6 | + describe('not configured', function() { |
| 7 | + |
| 8 | + it('should report with undefined', function() { |
| 9 | + global.expect(function() { |
| 10 | + checker.configure({requireParamDescription: undefined}); |
| 11 | + }).to.throws(/accepted value/i); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should report with an object', function() { |
| 15 | + global.expect(function() { |
| 16 | + checker.configure({requireParamDescription: {}}); |
| 17 | + }).to.throws(/accepted value/i); |
| 18 | + }); |
| 19 | + |
| 20 | + }); |
| 21 | + |
| 22 | + describe('with true', function() { |
| 23 | + checker.rules({requireParamDescription: true}); |
| 24 | + |
| 25 | + checker.cases([ |
| 26 | + /* jshint ignore:start */ |
| 27 | + { |
| 28 | + it: 'should not report', |
| 29 | + code: function() { |
| 30 | + function yay(yey) { |
| 31 | + } |
| 32 | + } |
| 33 | + }, { |
| 34 | + it: 'should report missing jsdoc-param description for function', |
| 35 | + errors: 1, |
| 36 | + code: function () { |
| 37 | + var x = 1; |
| 38 | + /** |
| 39 | + * @param xxx |
| 40 | + */ |
| 41 | + function funcName(xxx) { |
| 42 | + // dummy |
| 43 | + } |
| 44 | + } |
| 45 | + }, { |
| 46 | + it: 'should report missing jsdoc-param description for method', |
| 47 | + errors: 1, |
| 48 | + code: function () { |
| 49 | + Cls.prototype = { |
| 50 | + /** |
| 51 | + * @param yyy |
| 52 | + */ |
| 53 | + run: function(xxx) { |
| 54 | + // dummy |
| 55 | + } |
| 56 | + }; |
| 57 | + } |
| 58 | + }, { |
| 59 | + it: 'should not report invalid jsdoc for method', |
| 60 | + code: function () { |
| 61 | + var x = 1; |
| 62 | + /** |
| 63 | + * @param {String} xxx description |
| 64 | + */ |
| 65 | + function funcName(xxx) { |
| 66 | + // dummy |
| 67 | + } |
| 68 | + } |
| 69 | + }, { |
| 70 | + it: 'should not report invalid jsdoc for function', |
| 71 | + code: function () { |
| 72 | + Cls.prototype = { |
| 73 | + /** |
| 74 | + * @param {String} xxx description |
| 75 | + */ |
| 76 | + run: function(xxx) { |
| 77 | + // dummy |
| 78 | + } |
| 79 | + }; |
| 80 | + } |
| 81 | + }, { |
| 82 | + it: 'should not report invalid jsdoc with object type for method', |
| 83 | + code: function () { |
| 84 | + var x = 1; |
| 85 | + /** |
| 86 | + * @param {{foo: string}} xxx description |
| 87 | + */ |
| 88 | + function funcName(xxx) { |
| 89 | + // dummy |
| 90 | + } |
| 91 | + } |
| 92 | + }, { |
| 93 | + it: 'should not report invalid jsdoc with object type for function', |
| 94 | + code: function () { |
| 95 | + Cls.prototype = { |
| 96 | + /** |
| 97 | + * @param {{foo: string}} xxx description |
| 98 | + */ |
| 99 | + run: function(xxx) { |
| 100 | + // dummy |
| 101 | + } |
| 102 | + }; |
| 103 | + } |
| 104 | + }, { |
| 105 | + it: 'should not report invalid jsdoc with no param type for method', |
| 106 | + code: function () { |
| 107 | + var x = 1; |
| 108 | + /** |
| 109 | + * @param xxx description |
| 110 | + */ |
| 111 | + function funcName(xxx) { |
| 112 | + // dummy |
| 113 | + } |
| 114 | + } |
| 115 | + }, { |
| 116 | + it: 'should not report invalid jsdoc with no param type for function', |
| 117 | + code: function () { |
| 118 | + Cls.prototype = { |
| 119 | + /** |
| 120 | + * @param xxx description |
| 121 | + */ |
| 122 | + run: function(xxx) { |
| 123 | + // dummy |
| 124 | + } |
| 125 | + }; |
| 126 | + } |
| 127 | + }, { |
| 128 | + it: 'should report with right location', |
| 129 | + code: function () { |
| 130 | + Cls.prototype = { |
| 131 | + /** |
| 132 | + * @param xxx |
| 133 | + */ |
| 134 | + run: function(xxx) { |
| 135 | + // dummy |
| 136 | + } |
| 137 | + }; |
| 138 | + }, |
| 139 | + errors: {column: 17, line: 3} |
| 140 | + } |
| 141 | + /* jshint ignore:end */ |
| 142 | + ]); |
| 143 | + |
| 144 | + }); |
| 145 | + |
| 146 | +}); |
0 commit comments