All files / packages/design-system/ui/shared/helpers/prop-types is-dependent-on.js

100% Statements 3/3
100% Branches 4/4
100% Functions 0/0
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31            380x           1x                           108x        
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
 
const IsDependentOn = (dependentPropName, propType) => {
  return function(props, propName, componentName, ...rest) {
    if (props[propName] === undefined || props[propName] === null) {
      return;
    }
    if (
      props[dependentPropName] === undefined ||
      props[dependentPropName] === null
    ) {
      return new Error(
        'Invalid prop `' +
          propName +
          '` (has value `' +
          props[propName] +
          '`) supplied to `' +
          componentName +
          '`. Must set `' +
          dependentPropName +
          '` when setting `' +
          propName +
          '`'
      );
    }
    return propType(props, propName, componentName, ...rest);
  };
};
export default IsDependentOn;