@chubbyjs/chubbyjs-mock
Version:
A very strict mocking library for class based objects.
97 lines (96 loc) • 2.84 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Call {
constructor(method) {
this.hasWithValue = false;
this.hasReturnSelfValue = false;
this.hasReturnValue = false;
this.method = method;
}
static create(method) {
return new Call(method);
}
with(...withValue) {
this.hasWithValue = true;
this.withValue = withValue;
return this;
}
willThrowError(error) {
if (this.hasReturnSelfValue) {
throw new Error('willThrowError: There is already a return self');
}
if (this.hasReturnValue) {
throw new Error('willThrowError: There is already a return');
}
if (this.returnCallbackValue) {
throw new Error('willThrowError: There is already a return callback');
}
this.error = error;
return this;
}
willReturnSelf() {
if (this.error) {
throw new Error('willReturnSelf: There is already a error');
}
if (this.hasReturnValue) {
throw new Error('willReturnSelf: There is already a return');
}
if (this.returnCallbackValue) {
throw new Error('willReturnSelf: There is already a return callback');
}
this.hasReturnSelfValue = true;
return this;
}
willReturn(returnValue) {
if (this.error) {
throw new Error('willReturn: There is already a error');
}
if (this.hasReturnSelfValue) {
throw new Error('willReturn: There is already a return self');
}
if (this.returnCallbackValue) {
throw new Error('willReturn: There is already a return callback');
}
this.hasReturnValue = true;
this.returnValue = returnValue;
return this;
}
willReturnCallback(returnCallback) {
if (this.error) {
throw new Error('willReturnCallback: There is already a error');
}
if (this.hasReturnSelfValue) {
throw new Error('willReturnCallback: There is already a return self');
}
if (this.hasReturnValue) {
throw new Error('willReturnCallback: There is already a return');
}
this.returnCallbackValue = returnCallback;
return this;
}
getMethod() {
return this.method;
}
hasWith() {
return this.hasWithValue;
}
hasReturnSelf() {
return this.hasReturnSelfValue;
}
hasReturn() {
return this.hasReturnValue;
}
getWith() {
return this.withValue;
}
getError() {
return this.error;
}
getReturn() {
return this.returnValue;
}
getReturnCallback() {
return this.returnCallbackValue;
}
}
exports.default = Call;