If you really want to buy into the module pattern, it seems like anything that's enough of a unit that you'd want to test could be in its own module. In the example given, the sum function could be its own module that you require into the stats module. That way you could test them independently, and the stats module could simply expose its own appropriate methods. This has the added benefit of making the sum function…
That's a great point. I definitely agree that erring on the side of modules is better. I just worry about times when the purpose of a module is not clearly defined at the outset (e.g. when it only contains one function that is only used in one other module). I have often seen that devolve into the "helper" module, where random functions collect. I'm also not sure I buy the assertion that all code you would want to te…
All code you would want to test (or, even, to have exist) is either code that is in publicly exported functions or code whose pathways can all be exercised via interaction with the publicly exported interfaces, since code pathways that are neither in publicly exported functions nor reachable through publicly exported functions is dead code.
If its not testable via the public interface, it shouldn't exist.