|
| 1 | +/* eslint-env mocha */ |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +const assert = require('assert'); |
| 5 | +const propWrapperUtil = require('../../lib/util/propWrapper'); |
| 6 | + |
| 7 | +describe('PropWrapperFunctions', () => { |
| 8 | + describe('getPropWrapperFunctions', () => { |
| 9 | + it('returns set of functions if setting exists', () => { |
| 10 | + const propWrapperFunctions = ['Object.freeze', { |
| 11 | + property: 'forbidExtraProps' |
| 12 | + }]; |
| 13 | + const context = { |
| 14 | + settings: { |
| 15 | + propWrapperFunctions: propWrapperFunctions |
| 16 | + } |
| 17 | + }; |
| 18 | + assert.deepStrictEqual(propWrapperUtil.getPropWrapperFunctions(context), new Set(propWrapperFunctions)); |
| 19 | + }); |
| 20 | + |
| 21 | + it('returns empty array if no setting', () => { |
| 22 | + const context = { |
| 23 | + settings: {} |
| 24 | + }; |
| 25 | + assert.deepStrictEqual(propWrapperUtil.getPropWrapperFunctions(context), new Set([])); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('isPropWrapperFunction', () => { |
| 30 | + it('with string', () => { |
| 31 | + const context = { |
| 32 | + settings: { |
| 33 | + propWrapperFunctions: ['Object.freeze'] |
| 34 | + } |
| 35 | + }; |
| 36 | + assert.equal(propWrapperUtil.isPropWrapperFunction(context, 'Object.freeze'), true); |
| 37 | + }); |
| 38 | + |
| 39 | + it('with Object with object and property keys', () => { |
| 40 | + const context = { |
| 41 | + settings: { |
| 42 | + propWrapperFunctions: [{ |
| 43 | + property: 'freeze', |
| 44 | + object: 'Object' |
| 45 | + }] |
| 46 | + } |
| 47 | + }; |
| 48 | + assert.equal(propWrapperUtil.isPropWrapperFunction(context, 'Object.freeze'), true); |
| 49 | + }); |
| 50 | + |
| 51 | + it('with Object with only property key', () => { |
| 52 | + const context = { |
| 53 | + settings: { |
| 54 | + propWrapperFunctions: [{ |
| 55 | + property: 'forbidExtraProps' |
| 56 | + }] |
| 57 | + } |
| 58 | + }; |
| 59 | + assert.equal(propWrapperUtil.isPropWrapperFunction(context, 'forbidExtraProps'), true); |
| 60 | + }); |
| 61 | + }); |
| 62 | +}); |
0 commit comments