earljs
Version:
Ergonomic, modern and type-safe assertion library
33 lines (32 loc) • 1.07 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectWithMatcher = void 0;
const format_1 = require("../format");
const isEqual_1 = require("../isEqual");
const Base_1 = require("./Base");
function isObject(value) {
return value != null && (typeof value === 'object' || typeof value === 'function');
}
class ObjectWithMatcher extends Base_1.Matcher {
constructor(subset) {
super();
this.subset = subset;
}
check(actualItem) {
if (!isObject(actualItem)) {
return false;
}
const expectedEntries = Object.entries(this.subset);
return expectedEntries.every(([expectedKey, expectedValue]) => {
const actualValue = actualItem[expectedKey];
return (0, isEqual_1.isEqual)(actualValue, expectedValue);
});
}
toString() {
return `[ObjectWith: ${(0, format_1.formatCompact)(this.subset)}]`;
}
static make(subset) {
return new ObjectWithMatcher(subset);
}
}
exports.ObjectWithMatcher = ObjectWithMatcher;
;