@contract-case/case-core
Version:
Core functionality for the ContractCase contract testing suite
23 lines • 2.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EachArrayEntryMatches = void 0;
const case_plugin_base_1 = require("@contract-case/case-plugin-base");
const strip = (matcher, matchContext) => '_case:matcher:example' in matcher
? matchContext.descendAndStrip(matcher['_case:matcher:example'], (0, case_plugin_base_1.addLocation)(`:eachEntryLike[example]`, matchContext))
: [
matchContext.descendAndStrip(matcher['_case:matcher:matcher'], (0, case_plugin_base_1.addLocation)(`:eachEntryLike[matcher]`, matchContext)),
];
const check = async (matcher, matchContext, actual) => (0, case_plugin_base_1.combineResults)(Array.isArray(actual)
? (0, case_plugin_base_1.combineResults)(actual.length !== 0
? (await Promise.all(actual
.map((actualEntry, index) => matchContext.descendAndCheck(matcher['_case:matcher:matcher'], (0, case_plugin_base_1.addLocation)(`:eachEntryLike[${index}]`, matchContext), actualEntry))
.flat())).flat()
: (0, case_plugin_base_1.makeResults)((0, case_plugin_base_1.matchingError)(matcher, `Expected a non-empty array. It's not valid to use eachArrayEntryMatches for empty arrays. See the documentation for more details:\n\n https://case.contract-testing.io/docs/faq#how-do-i-test-an-array-field-that-might-have-zero-items-in-it`, actual, matchContext)))
: (0, case_plugin_base_1.makeResults)((0, case_plugin_base_1.matchingError)(matcher, `'${typeof actual}' is not an array`, actual, matchContext)));
exports.EachArrayEntryMatches = {
describe: (matcher, matchContext) => `an array where each entry matches ${matchContext.descendAndDescribe(matcher['_case:matcher:matcher'], (0, case_plugin_base_1.addLocation)(`:eachEntryLike`, matchContext))}`,
check,
strip,
validate: (matcher, matchContext) => matchContext.descendAndValidate(matcher['_case:matcher:matcher'], (0, case_plugin_base_1.addLocation)(`:eachEntryLike`, matchContext)),
};
//# sourceMappingURL=EachArrayEntryMatches.js.map