UNPKG

@contract-case/case-core

Version:

Core functionality for the ContractCase contract testing suite

25 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ObjectEachValueMatches = void 0; const case_plugin_base_1 = require("@contract-case/case-plugin-base"); const objectTests_1 = require("./internals/objectTests"); const strip = (matcher, matchContext) => '_case:matcher:example' in matcher ? matchContext.descendAndStrip(matcher['_case:matcher:example'], (0, case_plugin_base_1.addLocation)(`:objectEachValueLike[example]`, matchContext)) : { someKey: matchContext.descendAndStrip(matcher['_case:matcher:matcher'], (0, case_plugin_base_1.addLocation)(`:objectEachValueLike[matcher]`, matchContext)), }; const check = async (matcher, matchContext, actual) => [ ...((0, objectTests_1.isObject)(actual) ? (0, case_plugin_base_1.combineResults)(Object.entries(actual).length === 0 ? (0, case_plugin_base_1.makeResults)((0, case_plugin_base_1.matchingError)(matcher, // TODO: Add documentation `Expected an object with at least one key property. It's not valid to use objectEachValueMatches for empty objects. See the documentation for more details`, actual, matchContext)) : (await Promise.all(Object.entries(actual).map(([actualKey, actualValue]) => Promise.resolve(matchContext.descendAndCheck(matcher['_case:matcher:matcher'], (0, case_plugin_base_1.addLocation)(actualKey, matchContext), actualValue))))).flat()) : (0, case_plugin_base_1.makeResults)((0, case_plugin_base_1.matchingError)(matcher, (0, objectTests_1.whyNotAnObject)(actual), actual, matchContext))), ]; exports.ObjectEachValueMatches = { describe: (matcher, context) => `an object where each value is ${context.descendAndDescribe(matcher['_case:matcher:matcher'], (0, case_plugin_base_1.addLocation)(':eachValueLike', context))}`, check, strip, validate: (matcher, matchContext) => matchContext.descendAndValidate(matcher['_case:matcher:matcher'], (0, case_plugin_base_1.addLocation)(`:eachValueLike`, matchContext)), }; //# sourceMappingURL=ObjectEachValueMatches.js.map