stu
Version:
Stub dependencies when testing
34 lines • 1.17 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mockFunction_1 = __importDefault(require("./mockFunction"));
const getObjectKeys_1 = __importDefault(require("./getObjectKeys"));
const mockObject = (obj, keys, cache = new WeakMap()) => {
const mock = {};
keys.forEach((key) => {
const val = obj[key];
let mockVal;
if (cache.has(val)) {
mockVal = cache.get(val);
}
else if (typeof val === 'function') {
cache.set(val, null);
mockVal = mockFunction_1.default(val, cache);
cache.set(val, mockVal);
}
else if (typeof val === 'object' && val !== null) {
cache.set(val, null);
mockVal = mockObject(val, getObjectKeys_1.default(val), cache);
cache.set(val, mockVal);
}
else {
mockVal = val;
}
mock[key] = mockVal;
});
return mock;
};
exports.default = mockObject;
//# sourceMappingURL=mockObject.js.map