assertthat
Version:
assertthat provides fluent TDD.
27 lines (26 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertStringIsContainingAllOfIterable = void 0;
const errors_1 = require("../../errors");
const assertStringIsContainingString_1 = require("./assertStringIsContainingString");
const prettyPrint_1 = require("../../prettyPrint/typeAware/prettyPrint");
const defekt_1 = require("defekt");
const assertStringIsContainingAllOfIterable = function (actual, iterable) {
const missingItems = new Set();
for (const expectedItem of iterable) {
const result = (0, assertStringIsContainingString_1.assertStringIsContainingString)(actual, expectedItem);
if (result.hasError()) {
missingItems.add(expectedItem);
}
}
if (missingItems.size === 0) {
return (0, defekt_1.value)();
}
return (0, defekt_1.error)(new errors_1.AssertionFailed({
message: 'The string does not contain all expected sub-strings.',
actual: (0, prettyPrint_1.prettyPrint)(actual),
expected: `To contain all of:\n${(0, prettyPrint_1.prettyPrint)(iterable)}`,
diff: `Missing these sub-strings:\n${(0, prettyPrint_1.prettyPrint)(missingItems)}`
}));
};
exports.assertStringIsContainingAllOfIterable = assertStringIsContainingAllOfIterable;