@johanblumenberg/ts-mockito
Version:
Mocking library for TypeScript
89 lines • 4.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MethodStubSetter = void 0;
var CallFunctionMethodStub_1 = require("./stub/CallFunctionMethodStub");
var RejectPromiseMethodStub_1 = require("./stub/RejectPromiseMethodStub");
var ResolvePromiseMethodStub_1 = require("./stub/ResolvePromiseMethodStub");
var ReturnValueMethodStub_1 = require("./stub/ReturnValueMethodStub");
var ThrowErrorMethodStub_1 = require("./stub/ThrowErrorMethodStub");
var MethodStubSetter = (function () {
function MethodStubSetter(methodToStub) {
this.methodToStub = methodToStub;
methodToStub.watcher.invoked();
this.groupIndex = ++MethodStubSetter.globalGroupIndex;
}
MethodStubSetter.prototype.thenReturn = function () {
var _this = this;
var rest = [];
for (var _i = 0; _i < arguments.length; _i++) {
rest[_i] = arguments[_i];
}
if (rest.length === 0) {
rest.push(undefined);
}
rest.forEach(function (value) {
_this.methodToStub.methodStubCollection.add(new ReturnValueMethodStub_1.ReturnValueMethodStub(_this.groupIndex, _this.methodToStub.matchers, value));
});
return this;
};
MethodStubSetter.prototype.thenReturnOnce = function (value) {
this.methodToStub.methodStubCollection.add(new ReturnValueMethodStub_1.ReturnValueMethodStub(this.groupIndex, this.methodToStub.matchers, value, true));
return this;
};
MethodStubSetter.prototype.thenThrow = function () {
var _this = this;
var rest = [];
for (var _i = 0; _i < arguments.length; _i++) {
rest[_i] = arguments[_i];
}
rest.forEach(function (error) {
_this.methodToStub.methodStubCollection.add(new ThrowErrorMethodStub_1.ThrowErrorMethodStub(_this.groupIndex, _this.methodToStub.matchers, error));
});
return this;
};
MethodStubSetter.prototype.thenThrowOnce = function (error) {
this.methodToStub.methodStubCollection.add(new ThrowErrorMethodStub_1.ThrowErrorMethodStub(this.groupIndex, this.methodToStub.matchers, error, true));
return this;
};
MethodStubSetter.prototype.thenCall = function (func) {
this.methodToStub.methodStubCollection.add(new CallFunctionMethodStub_1.CallFunctionMethodStub(this.groupIndex, this.methodToStub.matchers, this.methodToStub, func));
return this;
};
MethodStubSetter.prototype.thenResolve = function () {
var _this = this;
var rest = [];
for (var _i = 0; _i < arguments.length; _i++) {
rest[_i] = arguments[_i];
}
if (rest.length === 0) {
rest.push(undefined);
}
rest.forEach(function (value) {
_this.methodToStub.methodStubCollection.add(new ResolvePromiseMethodStub_1.ResolvePromiseMethodStub(_this.groupIndex, _this.methodToStub.matchers, value));
});
return this;
};
MethodStubSetter.prototype.thenResolveOnce = function (value) {
this.methodToStub.methodStubCollection.add(new ResolvePromiseMethodStub_1.ResolvePromiseMethodStub(this.groupIndex, this.methodToStub.matchers, value, true));
return this;
};
MethodStubSetter.prototype.thenReject = function () {
var _this = this;
var rest = [];
for (var _i = 0; _i < arguments.length; _i++) {
rest[_i] = arguments[_i];
}
rest.forEach(function (error) {
_this.methodToStub.methodStubCollection.add(new RejectPromiseMethodStub_1.RejectPromiseMethodStub(_this.groupIndex, _this.methodToStub.matchers, error));
});
return this;
};
MethodStubSetter.prototype.thenRejectOnce = function (error) {
this.methodToStub.methodStubCollection.add(new RejectPromiseMethodStub_1.RejectPromiseMethodStub(this.groupIndex, this.methodToStub.matchers, error, true));
return this;
};
MethodStubSetter.globalGroupIndex = 0;
return MethodStubSetter;
}());
exports.MethodStubSetter = MethodStubSetter;
//# sourceMappingURL=MethodStubSetter.js.map