Timer-shim is a lightweight wrapper around setTimeout, setInterval, and clearTimeout/clearInterval that facilitates testing time-dependent code without modifying global state. It provides multiple aliases (e.g., timer.timeout, timer.to, timer.t) for convenience and validates arguments against NaN and non-function values. Version 0.3.0 is stable but appears unmaintained (last release 2012). Unlike sinon's fake timers, timer-shim only stubs calls without advancing time. Its key differentiator is simplicity and avoidance of global overrides, making it suitable for isolated unit tests.
npm install timer-shimVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of timer.interval and timer.timeout, then shows how to stub timer.timeout with sinon for testing.
Consider using sinon.useFakeTimers or lolex for modern timer testing.
Be consistent: use (delay, function) to avoid ambiguity.
Create a custom .d.ts file or use @ts-ignore.
Use timer.clear for both, but note that it internally calls clearTimeout. Works for both since handles are just numbers.
Ensure the package is installed and use require('timer-shim'). For ES6, use const timer = require('timer-shim');Verify the require statement: const timer = require('timer-shim'); then call timer.clear(handle);Add: const timer = require('timer-shim'); at the top of the file.No dependency data recorded yet.