Comment

Comment by BoiledCabbage

Dependency injection of just the function you need is good, but is still the second best approach.

The best approach is separating the calling of the external dependency (getting the time) to it's own function, and pass in the results of that call to your main function. Then test your main function. Ie approach 5. This eliminates the need for mocks and creates better factored code.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton