|
| 1 | +var Checker = require('../../../lib/checker'); |
| 2 | +var expect = require('chai').expect; |
| 3 | + |
| 4 | +describe('rules/disallow-var', function() { |
| 5 | + describe('when { disallowVar: true }', function() { |
| 6 | + it('disallows `var` declarations', function() { |
| 7 | + var checker = buildChecker({ disallowVar: true }); |
| 8 | + |
| 9 | + expect(checker.checkString('var foo;')).to.have.one.validation.error.from('disallowVar'); |
| 10 | + }); |
| 11 | + |
| 12 | + it('allows `let` declarations', function() { |
| 13 | + var checker = buildChecker({ disallowVar: true }); |
| 14 | + |
| 15 | + expect(checker.checkString('let foo;')).to.have.no.errors(); |
| 16 | + }); |
| 17 | + |
| 18 | + it('allows `const` declarations', function() { |
| 19 | + var checker = buildChecker({ disallowVar: true }); |
| 20 | + |
| 21 | + expect(checker.checkString('const foo = 1;')).to.have.no.errors(); |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + describe('when { disallowVar: false }', function() { |
| 26 | + it('allows `var` declarations', function() { |
| 27 | + var checker = buildChecker({ disallowVar: false }); |
| 28 | + |
| 29 | + expect(checker.checkString('var foo;')).to.have.no.errors(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('allows `let` declarations', function() { |
| 33 | + var checker = buildChecker({ disallowVar: false }); |
| 34 | + |
| 35 | + expect(checker.checkString('let foo;')).to.have.no.errors(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('allows `const` declarations', function() { |
| 39 | + var checker = buildChecker({ disallowVar: false }); |
| 40 | + |
| 41 | + expect(checker.checkString('const foo = 1;')).to.have.no.errors(); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + function buildChecker(rules) { |
| 46 | + var checker = new Checker(); |
| 47 | + checker.registerDefaultRules(); |
| 48 | + checker.configure(rules); |
| 49 | + |
| 50 | + return checker; |
| 51 | + } |
| 52 | +}); |
0 commit comments