|
| 1 | +var Checker = require('../../../lib/checker'); |
| 2 | +var expect = require('chai').expect; |
| 3 | + |
| 4 | +describe('rules/require-object-destructuring', function() { |
| 5 | + describe('when { requireObjectDestructuring: true }', function() { |
| 6 | + it('disallows direct property access/assignment', function() { |
| 7 | + var checker = buildChecker({ requireObjectDestructuring: true }); |
| 8 | + |
| 9 | + expect(checker.checkString('var foo = SomeThing.foo;')). |
| 10 | + to.have.one.validation.error.from('requireObjectDestructuring'); |
| 11 | + }); |
| 12 | + |
| 13 | + it('disallows nested property access/assignment', function() { |
| 14 | + var checker = buildChecker({ requireObjectDestructuring: true }); |
| 15 | + |
| 16 | + expect(checker.checkString('var bar = SomeThing.foo.bar;')). |
| 17 | + to.have.one.validation.error.from('requireObjectDestructuring'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('disallows access/assignment with a string literal', function() { |
| 21 | + var checker = buildChecker({ requireObjectDestructuring: true }); |
| 22 | + |
| 23 | + expect(checker.checkString('var val = SomeThing["some.key"].val;')). |
| 24 | + to.have.one.validation.error.from('requireObjectDestructuring'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('allows destructuring direct property access/assignment', function() { |
| 28 | + var checker = buildChecker({ requireObjectDestructuring: true }); |
| 29 | + |
| 30 | + expect(checker.checkString('var { foo } = SomeThing;')).to.have.no.errors(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('allows destructuring nested property access/assignment', function() { |
| 34 | + var checker = buildChecker({ requireObjectDestructuring: true }); |
| 35 | + |
| 36 | + expect(checker.checkString('var { bar } = SomeThing.foo;')).to.have.no.errors(); |
| 37 | + }); |
| 38 | + |
| 39 | + it('allows destructuring access/assignment with a string literal', function() { |
| 40 | + var checker = buildChecker({ requireObjectDestructuring: true }); |
| 41 | + |
| 42 | + expect(checker.checkString('var { val } = SomeThing["some.key"];')).to.have.no.errors(); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + function buildChecker(rules) { |
| 47 | + var checker = new Checker(); |
| 48 | + checker.registerDefaultRules(); |
| 49 | + checker.configure(rules); |
| 50 | + |
| 51 | + return checker; |
| 52 | + } |
| 53 | +}); |
0 commit comments