alsatian
Version:
TypeScript and JavaScript testing framework for beautiful and readable tests
33 lines • 1.63 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const matcher_1 = require("./matcher");
var LimitType;
(function (LimitType) {
LimitType[LimitType["LessThan"] = 0] = "LessThan";
LimitType[LimitType["GreaterThan"] = 1] = "GreaterThan";
})(LimitType || (LimitType = {}));
class NumberMatcher extends matcher_1.Matcher {
toBeLessThan(upperLimit) {
this._matchAgainstLimit(upperLimit, LimitType.LessThan);
}
toBeGreaterThan(lowerLimit) {
this._matchAgainstLimit(lowerLimit, LimitType.GreaterThan);
}
_matchAgainstLimit(limit, limitType) {
const limitTypeName = LimitType[limitType];
this._validateValues(limit, `toBe${LimitType[limitType]}`, `${limitType === LimitType.LessThan ? "upper" : "lower"} limit`);
const readableLimitType = limitTypeName.replace(/([a-z])([A-Z])/, "$1 $2").toLowerCase();
const exceedsLimit = limitType === LimitType.LessThan ? this.actualValue < limit : this.actualValue > limit;
this._registerMatcher(exceedsLimit === this.shouldMatch, `Expected ${this.actualValue} ${!this.shouldMatch ? "not " : ""}to be ${readableLimitType} ${limit}.`, `a number ${!this.shouldMatch ? "not " : ""}${readableLimitType} ${limit}`, {
actual: this.actualValue,
limit
});
}
_validateValues(limit, functionName, limitType) {
if (limit === null || limit === undefined) {
throw new TypeError(`${functionName} ${limitType} must not be null or undefined.`);
}
}
}
exports.NumberMatcher = NumberMatcher;
//# sourceMappingURL=number-matcher.js.map
;