assertthat
Version:
assertthat provides fluent TDD.
27 lines (26 loc) • 1.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertArrayIsNotContainingAnyOfIterable = 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 assertArrayIsNotContainingAnyOfIterable = function (actual, iterable) {
const dispelledActual = (0, dispel_1.dispel)(actual);
const dispelledExpected = (0, dispel_1.dispel)(iterable);
const setFromActual = new Set(dispelledActual);
const setFromExpected = new Set(dispelledExpected);
const diff = (0, compareSets_1.compareSets)(setFromActual, setFromExpected);
if (!(0, EqualDiff_1.isEqualDiff)(diff) && diff.equal.size === 0) {
return (0, defekt_1.value)();
}
return (0, defekt_1.error)(new errors_1.AssertionFailed({
message: 'The array contains one or more of the items in the iterable.',
actual: (0, prettyPrint_1.prettyPrint)(dispelledActual),
expected: `To not contain any of:\n${(0, prettyPrint_1.prettyPrint)(dispelledExpected)}`,
diff: `These items are contained, but should not be:\n${(0, prettyPrint_1.prettyPrint)((0, EqualDiff_1.isEqualDiff)(diff) ? setFromExpected : diff.equal)}`
}));
};
exports.assertArrayIsNotContainingAnyOfIterable = assertArrayIsNotContainingAnyOfIterable;