Developer builds TypeScript TimeProvider to eliminate date-mocking pain in tests
A developer frustrated with the complexity of mocking JavaScript's Date object in tests has built an open-source TypeScript library called TimeProvider. The library treats the current time as an injectable dependency — similar to a database or HTTP client — rather than a global API that needs to be patched. Beyond replacing new Date(), the abstraction also covers setTimeout, setInterval, and performance measurements. The approach mirrors a TimeProvider abstraction introduced in .NET 8, which the developer cited as validation of the concept. The project is publicly available, and the author is seeking feedback from the TypeScript community on whether dependency-injected time is preferable to conventional fake timers.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in