cli-testing-library
Version:
Simple and complete CLI testing utilities that encourage good testing practices.
49 lines (48 loc) • 1.2 kB
JavaScript
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;
},
{}
);
}
export {
bindObjectFnsToInstance,
debounce,
getCurrentInstance,
jestFakeTimersAreEnabled,
setCurrentInstance
};
//# sourceMappingURL=helpers.js.map