@chubbyjs/chubbyjs-mock
Version:
A very strict mocking library for class based objects.
32 lines (31 loc) • 1.09 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const AbstractArgument_1 = require("./AbstractArgument");
class ArgumentInstanceOf extends AbstractArgument_1.default {
constructor(type) {
super();
this.type = type;
}
assert(argument) {
if (typeof this.type === 'function') {
// function
if (typeof argument === 'function') {
if (argument.name !== this.type.name) {
throw new Error(`Expected type ${this.type.name}, given type ${argument.name}`);
}
}
// class based object
else {
if (!(argument instanceof this.type)) {
throw new Error(`Expected type ${this.type.name}, given type ${argument.constructor.name}`);
}
}
}
else {
if (typeof argument !== this.type) {
throw new Error(`Expected type ${this.type}, given type ${typeof argument}`);
}
}
}
}
exports.default = ArgumentInstanceOf;
;