The visibone browser link offers what they call "confidence." This basically gives a suggestion on how to implement unit testing for JavaScript. It is really very simple.
See the lower right side of the following image link:
http://www.visibone.com/products/ebk8-9_850.jpg
To summarize here:
Create the assert () function:
function assert(fact, details){ if (!fact) alert("Assert failure: " + details); }
And you could call it something like this:
assert((parseInt("1") == 1), "Check string '1' is equal to integer 1");
Or perhaps with a better comparison ===:
assert((parseInt("1") === 1), "Check string '1' is equal to integer 1");
There is more in the linked picture, and your assert functions may become more sophisticated.
I did a Google search on the “JavaScript assert” and got quite a few links, so it might be worth checking out.
James wiseman
source share