alsatian
Version:
TypeScript and JavaScript testing framework for beautiful and readable tests
27 lines • 1.03 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const matcher_1 = require("./matcher");
const stringification_1 = require("../stringification");
class EmptyMatcher extends matcher_1.Matcher {
toBeEmpty() {
const actualValue = this.actualValue;
const length = this._getLength(actualValue);
this._registerMatcher((length === 0) === this.shouldMatch, `Expected "${typeof actualValue === "string"
? actualValue
: stringification_1.stringify(actualValue)}" ` + `${this.shouldMatch ? "" : "not "}to be empty.`, "value to be empty", {
actualLength: length,
expectedLength: this.shouldMatch ? 0 : "> 0"
});
}
_getLength(value) {
if (value instanceof Map) {
return value.size;
}
if (value.length !== undefined) {
return value.length;
}
return Object.keys(value).length;
}
}
exports.EmptyMatcher = EmptyMatcher;
//# sourceMappingURL=empty-matcher.js.map
;