"use strict";
var exact_match_error_1 = require("./errors/exact-match-error");
var equal_match_error_1 = require("./errors/equal-match-error");
var regex_match_error_1 = require("./errors/regex-match-error");
var truthy_match_error_1 = require("./errors/truthy-match-error");
var contents_match_error_1 = require("./errors/contents-match-error");
var less_than_match_error_1 = require("./errors/less-than-match-error");
var greater_than_match_error_1 = require("./errors/greater-than-match-error");
var error_match_error_1 = require("./errors/error-match-error");
var function_call_match_error_1 = require("./errors/function-call-match-error");
function Expect(actualValue) {
return new Matcher(actualValue);
}
exports.Expect = Expect;
var Matcher = (function () {
function Matcher(actualValue) {
this._shouldMatch = true;
this._actualValue = actualValue;
}
Object.defineProperty(Matcher.prototype, "not", {
get: function () {
this._shouldMatch = !this._shouldMatch;
return this;
},
enumerable: true,
configurable: true
});
Matcher.prototype.toBe = function (expectedValue) {
if (expectedValue !== this._actualValue === this._shouldMatch) {
throw new exact_match_error_1.ExactMatchError(this._actualValue, expectedValue, this._shouldMatch);
}
};
Matcher.prototype.toEqual = function (expectedValue) {
if (expectedValue != this._actualValue === this._shouldMatch) {
throw new equal_match_error_1.EqualMatchError(this._actualValue, expectedValue, this._shouldMatch);
}
};
Matcher.prototype.toMatch = function (regex) {
if (!regex.test(this._actualValue) === this._shouldMatch) {
throw new regex_match_error_1.RegexMatchError(this._actualValue, regex, this._shouldMatch);
}
};
Matcher.prototype.toBeDefined = function () {
if (this._actualValue === undefined === this._shouldMatch) {
throw new exact_match_error_1.ExactMatchError(this._actualValue, undefined, !this._shouldMatch);
}
};
Matcher.prototype.toBeNull = function () {
if (this._actualValue !== null === this._shouldMatch) {
throw new exact_match_error_1.ExactMatchError(this._actualValue, null, this._shouldMatch);
}
};
Matcher.prototype.toBeTruthy = function () {
if ((this._actualValue && !this._shouldMatch) || (!this._actualValue && this._shouldMatch)) {
throw new truthy_match_error_1.TruthyMatchError(this._actualValue, this._shouldMatch);
}
};
Matcher.prototype.toContain = function (expectedContent) {
if (this._actualValue.indexOf(expectedContent) === -1 === this._shouldMatch) {
throw new contents_match_error_1.ContentsMatchError(this._actualValue, expectedContent, this._shouldMatch);
}
};
Matcher.prototype.toBeLessThan = function (upperLimit) {
if (this._actualValue > upperLimit === this._shouldMatch) {
throw new less_than_match_error_1.LessThanMatchError(this._actualValue, upperLimit, this._shouldMatch);
}
};
Matcher.prototype.toBeGreaterThan = function (lowerLimit) {
if (this._actualValue < lowerLimit === this._shouldMatch) {
throw new greater_than_match_error_1.GreaterThanMatchError(this._actualValue, lowerLimit, this._shouldMatch);
}
};
Matcher.prototype.toThrow = function () {
var threwError = false;
var actualError;
try {
this._actualValue();
}
catch (error) {
actualError = error;
threwError = true;
}
if (!threwError === this._shouldMatch) {
throw new error_match_error_1.ErrorMatchError(actualError, this._shouldMatch);
}
};
Matcher.prototype.toThrowError = function (errorType, errorMessage) {
var threwRightError = false;
var actualError;
try {
this._actualValue();
}
catch (error) {
actualError = error;
if (error instanceof errorType && error.message === errorMessage) {
threwRightError = true;
}
}
if (!threwRightError === this._shouldMatch) {
throw new error_match_error_1.ErrorMatchError(actualError, this._shouldMatch, errorType, errorMessage);
}
};
Matcher.prototype.toHaveBeenCalled = function () {
if (this._actualValue.calls.length === 0 === this._shouldMatch) {
throw new function_call_match_error_1.FunctionCallMatchError(this._actualValue, this._shouldMatch);
}
};
Matcher.prototype.toHaveBeenCalledWith = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i - 0] = arguments[_i];
}
if (this._actualValue.calls.filter(function (call) { return call.args.filter(function (arg, index) { return arg === args[index]; }) && call.args.length === args.length; }).length === 0 === this._shouldMatch) {
throw new function_call_match_error_1.FunctionCallMatchError(this._actualValue, this._shouldMatch, args);
}
};
return Matcher;
}());
//# sourceMappingURL=expect.js.map |