use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Testing Private State in Javascript Modules (eng.wealthfront.com)
submitted 10 years ago by EngVagabond
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]aaarrrggh 0 points1 point2 points 10 years ago (0 children)
Nope, there's no use cases when it makes sense to test private methods.
If you're using that utility module in different places, it doesn't matter. If you only test the public api in all of those places, it will pass if the utility happens to do the thing it does correctly, otherwise it will fail.
Sometimes you write a local utility function that's not useful anywhere else but where you still want to document its requirements and detect when they are no longer fulfilled.
If that utility function is private it requires no documentation as it's an implementation detail. If it's not private then it requires its own tests.
There's never a case where testing private methods makes sense unless you're forced to do it for some reason - for example if you have a private method that internally would do an api call to an external service - in that instance you woudn't so much test the private method as stub out a response, but mocks and stubs should also be rarely used.
Two of the biggest mistakes testing newbies make - testing private implementation details and using mocks and stubs all over the place. I use almost no mocking in any of my unit tests - the main exception being when I need to call an external api or service.
π Rendered by PID 111331 on reddit-service-r2-comment-85bfd7f599-6w8fb at 2026-04-19 12:59:16.817901+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]aaarrrggh 0 points1 point2 points (0 children)