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]