mockingbird
Version:
Super Simple, Yet Powerful, TypeScript Library for Creating Mocks. Mockingbird allows you to create class mocks like a breeze with a simple yet powerful @Mock decorator
55 lines • 1.52 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MockBuilder = void 0;
const mock_producer_1 = require("./mock-producer");
class MockBuilder extends mock_producer_1.MockProducer {
constructor(targetClass) {
super(targetClass);
this.isPlain = false;
this.mutations = {};
this.omitKeys = [];
this.pickKeys = [];
}
clean() {
this.isPlain = false;
this.mutations = {};
this.omitKeys = [];
this.pickKeys = [];
}
plain() {
this.isPlain = true;
return this;
}
mutate(mutations) {
this.mutations = mutations;
return this;
}
/**
* @deprecated use .omit() instead
*/
ignore(...keys) {
return this.omit(...keys);
}
omit(...keys) {
this.omitKeys = keys;
return this;
}
pick(...keys) {
this.pickKeys = keys;
return this;
}
one() {
const { mutations, omitKeys, pickKeys, isPlain } = this;
const instance = super.createOne({ mutations, omit: omitKeys, plain: isPlain, pick: pickKeys });
this.clean();
return instance;
}
many(count) {
const { mutations, omitKeys, pickKeys, isPlain } = this;
const instances = super.createMany(count, { mutations, omit: omitKeys, plain: isPlain, pick: pickKeys });
this.clean();
return instances;
}
}
exports.MockBuilder = MockBuilder;
//# sourceMappingURL=mock-builder.js.map