All files / latest/src/helpers/pathElements/getKeys/src checkForError.js

100% Statements 18/18
100% Branches 5/5
100% Functions 2/2
100% Lines 18/18

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 191x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 15x 2x 2x 15x 1x 1x  
/**
 * Validate results, returns true if valid, false otherwise
*/
const areResultsInvalid = (results) => (!results || results.length === 0);
 
/**
 * Validate results and throw error on fatalError porperty
 * @param {Boolean} fatalError - true if fatal error should be thrown in case results are invalid
 * @param {Array} results - array of results
 * @returns {Error} if no results are provided or length of results is 0, and fatalError is true
 */
const checkForError = (fatalError, results) => {
  if (fatalError && areResultsInvalid(results)) {
    throw new Error('No element is found for provided wildcard.');
  }
};
 
module.exports = checkForError;