3 ms·
It is a very poor solution because you are coupling your tests to private implementation detail of the function you are testing. > but injecting the same depen
by jonahx 4y ago
It is a very poor solution because you are coupling your tests to private implementation detail of the function you are testing.
> but injecting the same dependency over and over in a codebase (IE, anywhere that makes an HTTP request) is bad ergonomics.
The production dep is the default one, as I noted, so it gets injected automatically without the calling code needing to even know about it. This has the benefit of explicitly documenting in the signature all your functions dependencies with side effects. This alone would make it worth it, even ignoring the benefits on your test code.
> to not get blocked
"not betting blocked" isn't a justification for bad approaches. In any case, what I am suggesting will be just as fast.
> and avoiding making src code changes to solely to accommodate tests.
You won't be. The only src code change you'd be making is to the function signature to explicitly document its dependencies, which you should have done from the beginning.
I will argue that having global, side effectful dependencies scattered across your code base is one of the worst errors you can make.