Also be sure to read this thread from earlier where Christian Johansen weighs in on this directly: http://groups.google.com/group/jsmentors/browse_thread/thread/da28fe220dea609/fd44ec9cf4223e03?hl=en&lnk=gst&q=testing#fd44ec9cf4223e03 From: [email protected] [mailto:[email protected]] On Behalf Of Nick Morgan Sent: Thursday, February 17, 2011 9:32 AM To: [email protected] Subject: Re: [JSMentors] Module pattern and testability
I think there's a chapter on this in Christian Johansen's Test-Driven JavaScript Development (tddjs.com<http://tddjs.com>). I'm not sure because I haven't got there yet, and I don't have the book with me, but I'm fairly sure it addresses this exact issue. On 17 February 2011 12:32, Matthias Reuter <[email protected]<mailto:[email protected]>> wrote: Hi all, I use the module pattern to keep the global object clean. Mostly, my modules are completely independant, so I do not use the revealing module pattern. (function () { function a () {} function b () {} }()); Now the question is, how do I unit-test function a and function b? Somehow I need to be able to access these functions, on the other hand I actually don't want these to be accessible, otherwise I wouldn't have chosen the module pattern. My first idea was to omit the immediate function which forms the module pattern in the source files, and wrap it around the module during the build process. Unfortunately, that would mean I would either have to build the application everytime I make a change, or I would have to carefully prevent variable name collisions during development. Which I don't want, that's why I'm using the module pattern. A different idea was to reveal all inner functions, if some global debug object is set: (function () { function a () {} function b () {} if (typeof _debug !== "undefined") { _debug.addModule({ "a" : a, "b" : b }, this); } }()); Now I'm not too happy about that approach either. So do you have any ideas how to test functions within a module? Matt -- 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]<mailto:jsmentors%[email protected]> -- Nick Morgan http://skilldrick.co.uk @skilldrick<http://twitter.com/skilldrick> -- 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]<mailto:[email protected]> -- 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]
