UNPKG

assertthat

Version:
29 lines (28 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assertSetIsContainingAllOfIterable = void 0; const errors_1 = require("../../errors"); const compareSets_1 = require("../../comparisons/forSets/compareSets"); const dispel_1 = require("../../dispel/dispel"); const EqualDiff_1 = require("../../diffs/EqualDiff"); const prettyPrint_1 = require("../../prettyPrint/typeAware/prettyPrint"); const defekt_1 = require("defekt"); const assertSetIsContainingAllOfIterable = function (actual, iterable) { const dispelledActual = (0, dispel_1.dispel)(actual); const dispelledExpected = (0, dispel_1.dispel)(iterable); const setFromExpected = new Set(dispelledExpected); const diff = (0, compareSets_1.compareSets)(dispelledActual, setFromExpected); if ((0, EqualDiff_1.isEqualDiff)(diff)) { return (0, defekt_1.value)(); } if (diff.omissions.size === 0) { return (0, defekt_1.value)(); } return (0, defekt_1.error)(new errors_1.AssertionFailed({ message: 'The set does not contain all expected items.', actual: (0, prettyPrint_1.prettyPrint)(dispelledActual), expected: `To contain all of:\n${(0, prettyPrint_1.prettyPrint)(dispelledExpected)}`, diff: `Missing these items:\n${(0, prettyPrint_1.prettyPrint)(diff.omissions)}` })); }; exports.assertSetIsContainingAllOfIterable = assertSetIsContainingAllOfIterable;