3 ms·
What you inject is up to you. In Angular.js you could inject setTimeout's interface. I've injected fetch (for automatic anti-CSRF header inclusion). Etc. Facad
by lhorie 5y ago
What you inject is up to you. In Angular.js you could inject setTimeout's interface. I've injected fetch (for automatic anti-CSRF header inclusion). Etc.
Facades are good if you're not sure if the API/semantics are set in stone.
For moment.js, one typically only cares to mock specific calls related to things like current time, so it often makes more sense to refactor towards turning currentness into an explicit input, either by mocking the hard-coded moment.js call inside a convoluted unit, or more ideally, by making the value an input argument by design in the first place.
The latter is harder to get to if you already have the code written, so mocking moment.js calls could be an acceptable alternative.
You don't need to bring the whole OOP factory manager baggage if you just want simple contracts.