Hi All,

We're trying to improve our processes and overall code quality at work by using 
TDD for all new Javascript code, while simultaneously retrofitting tests to our 
existing js codebase. We use a single global variable as a namespace within 
which multiple sub-modules are defined, mostly following the Revealing Module 
Pattern.

The problem we've struck is that the private helper functions within each 
module can't be accessed from outside the closure for unit testing. We could of 
course rely solely on our end-to-end tests to ensure correct behaviour, but 
we're striving for more comprehensive coverage than that. Alternatively we 
could expose all of these helper methods so that they can be properly tested, 
however that defeats one of the primary benefits the pattern, namely 
encapsulation. I'm loathe to do sacrifice one benefit for the other, and 
ideally want both.

The only other alternative I can think of is to modify the files at build time, 
perhaps exposing the private methods via a temporary test API object or by 
removing the outer containing function which constrains their scope. Of course, 
that would mean that we'd then be releasing a version of our code different 
from the one we'd tested ... which sort of defeats the purpose.

Any thoughts or experiences you have to share would be greatly appreciated. I'm 
a relative novice at TDD, so don't hesitate to mention anything you think seems 
obvious. Likewise, I'm only a third of the way through Christain Johansen's 
excellent book ... so feel free to tell me to at least finish that before 
asking such things, if appropriate ;-)

Cheers,
Mike

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to