UNPKG

assertthat

Version:
25 lines (24 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assertArrayIsContainingAnyOfIterable = void 0; const assertArrayIsContainingItem_1 = require("./assertArrayIsContainingItem"); const errors_1 = require("../../errors"); const dispel_1 = require("../../dispel/dispel"); const prettyPrint_1 = require("../../prettyPrint/typeAware/prettyPrint"); const defekt_1 = require("defekt"); const assertArrayIsContainingAnyOfIterable = function (actual, iterable) { const dispelledActual = (0, dispel_1.dispel)(actual); const dispelledExpected = (0, dispel_1.dispel)(iterable); for (const item of dispelledExpected) { const result = (0, assertArrayIsContainingItem_1.assertArrayIsContainingItem)(actual, item); if (result.hasValue()) { return (0, defekt_1.value)(); } } return (0, defekt_1.error)(new errors_1.AssertionFailed({ message: 'The array does not contain any of the expected items.', actual: (0, prettyPrint_1.prettyPrint)(dispelledActual), expected: `To contain any of:\n${(0, prettyPrint_1.prettyPrint)(dispelledExpected)}` })); }; exports.assertArrayIsContainingAnyOfIterable = assertArrayIsContainingAnyOfIterable;