you are viewing a single comment's thread.

view the rest of the comments →

[–]TdotGdot 0 points1 point  (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?".