src/helpers/describeSimpleSelector.js
/**
 * Helper that tests simple selectors and optionally their default values to help
 * reduce the amount of boilerplate test code in the unit test suite
 *
 * A simple selector is one which takes an attribute from an object
 *
 * @param {string} selectorName Name of the unit being tested
 * @param {function} selector Unit being tested
 * @param {string} nodeName Name of property to pull out of substate object
 * @param {*} [defaultValue] A non-undefined value the selector short circuits to if
 * the node is not found on the substate object
 */
Helper that tests simple selectors and optionally their default values to help
reduce the amount of boilerplate test code in the unit test suite

A simple selector is one which takes an attribute from an object

@param {string} selectorName Name of the unit being tested
@param {function} selector Unit being tested
@param {string} nodeName Name of property to pull out of substate object
@param {*} [defaultValue] A non-undefined value the selector short circuits to if
the node is not found on the substate object
Helper that tests simple selectors and optionally their default values to help reduce the amount of boilerplate test code in the unit test suite A simple selector is one which takes an attribute from an object @param { string } selectorName Name of the unit being tested @param { function } selector Unit being tested @param { string } nodeName Name of property to pull out of substate object @param { * } [ defaultValue ] A non - undefined value the selector short circuits to if the node is not found on the substate object
function describeSimpleSelector(selectorName, selector, nodeName, defaultValue) {
    describe(selectorName, () => {
        before(() => {
            if (_isUndefined(selector)) {
                throw new Error(`${selectorName} is undefined! Is it missing as a module index export?`);
            }
        });
        it('selects its node from the state tree', () => {
            const value = Symbol('foobar'); 
            const state = {};
            _set(state, nodeName, value);
            deepFreeze(state);
            expect(selector.resultFunc(state)).to.equal(value);
        });
        if (!_isUndefined(defaultValue)) {
            let defaultValueName = defaultValue.toString();
            if (typeof defaultValue === 'string') {
                defaultValueName = `"${defaultValueName}"`;
            }
            it(`gets a default value of ${defaultValueName} if node not found`, () => {
                expect(selector.resultFunc({}))
                    .to.eql(defaultValue);
            });
        }
    });
}
function describeSimpleSelector ( selectorName , selector , nodeName , defaultValue ) { describe ( selectorName , ( ) => { before ( ( ) => { if ( _isUndefined ( selector ) ) { throw new Error ( ` ${ selectorName } ` ) ; } } ) ; it ( 'selects its node from the state tree' , ( ) => { const value = Symbol ( 'foobar' ) ; const state = { } ; _set ( state , nodeName , value ) ; deepFreeze ( state ) ; expect ( selector . resultFunc ( state ) ) . to . equal ( value ) ; } ) ; if ( ! _isUndefined ( defaultValue ) ) { let defaultValueName = defaultValue . toString ( ) ; if ( typeof defaultValue === 'string' ) { defaultValueName = ` ${ defaultValueName } ` ; } it ( ` ${ defaultValueName } ` , ( ) => { expect ( selector . resultFunc ( { } ) ) . to . eql ( defaultValue ) ; } ) ; } } ) ; }
Helper that tests simple selectors and optionally their default values to help
 reduce the amount of boilerplate test code in the unit test suite
Helper that tests simple selectors and optionally their default values to help reduce the amount of boilerplate test code in the unit test suite
// Disallow SUT workarounds