UNPKG

softkave-js-utils

Version:

JavaScript & Typescript utility functions, types, and classes

29 lines 972 B
import { isArray } from 'lodash-es'; export function checkErrorHasName(error, expectedErrorNames, shouldMatchAtLeastOne = true) { const errorMap = (isArray(error) ? error : [error]).reduce((acc, nextError) => { if (nextError === null || nextError === void 0 ? void 0 : nextError.name) { acc[nextError.name] = nextError.name; } return acc; }, {}); const matchedNames = []; const missingNames = []; expectedErrorNames = isArray(expectedErrorNames) ? expectedErrorNames : [expectedErrorNames]; expectedErrorNames.forEach(name => { if (errorMap[name]) { matchedNames.push(name); } else { missingNames.push(name); } }); return { matchedNames, missingNames, matches: (shouldMatchAtLeastOne && matchedNames.length > 0) || missingNames.length === 0, }; } //# sourceMappingURL=checkErrorHasName.js.map