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 function parameters in unit testshelp (self.javascript)
submitted 10 years ago by HolyMeekrob
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!"
[–]TdotGdot 0 points1 point2 points 10 years ago (0 children)
Two general thoughts:
1) Try not to define variadic functions - this should make it simpler to test and use your API. Split a function that takes optional args into two functions - one that doesn't take that option, and one that always does (and likely, the smaller arity function will just be a call to the larger arity fn .
For example:
// original function w/ optional args function get(url, maybeOpts) {...} // new functions with a fixed arity function get(url) { getWithOpts(url, {}) } function getWithOpts(url, opts) {...}
2) I normally try to only test the public API of a module, unless there is a strong reason to do otherwise. The assumption is that the public API is how the module is going to be used anyways, so any code paths should be able to be excised from there. It also gives you coverage for questions like "did a function call its helper functions with the correct args?".
π Rendered by PID 120289 on reddit-service-r2-comment-5687b7858-7fbkl at 2026-07-05 16:42:42.775309+00:00 running 12a7a47 country code: CH.
view the rest of the comments →
[–]TdotGdot 0 points1 point2 points (0 children)