cli-testing-library
Version:
Simple and complete CLI testing utilities that encourage good testing practices.
49 lines (48 loc) • 1.41 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
function jestFakeTimersAreEnabled() {
if (typeof vi !== "undefined" && vi.isFakeTimers && vi.isFakeTimers() || typeof jest !== "undefined" && jest !== null) {
return (
// legacy timers
setTimeout._isMockFunction === true || // modern timers
Object.prototype.hasOwnProperty.call(setTimeout, "clock")
);
}
return false;
}
const instanceRef = { current: void 0 };
if (typeof afterEach === "function") {
afterEach(() => {
instanceRef.current = void 0;
});
}
function getCurrentInstance() {
return instanceRef.current;
}
function setCurrentInstance(newInstance) {
instanceRef.current = newInstance;
}
function debounce(func, timeout) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => {
func.apply(this, args);
}, timeout);
};
}
function bindObjectFnsToInstance(instance, object) {
return Object.entries(object).reduce(
(prev, [key, fn]) => {
prev[key] = (...props) => fn(instance, ...props);
return prev;
},
{}
);
}
exports.bindObjectFnsToInstance = bindObjectFnsToInstance;
exports.debounce = debounce;
exports.getCurrentInstance = getCurrentInstance;
exports.jestFakeTimersAreEnabled = jestFakeTimersAreEnabled;
exports.setCurrentInstance = setCurrentInstance;
//# sourceMappingURL=helpers.cjs.map