Wednesday, June 8, 2011

Jasmine Javascript debugging? Maybe not quite there...

Whew! Sorry about going dark for a while. Am no longer a consulting Tech Architect at Boeing Commercial Aircraft and just started in a SW Architect/Engineer position at Fabric WorldWide...

Inherited the responsibility for writing new and maintaining existing Javascript plugins used in BA/BI of websites. Lot's of interesting asynchronous code, not necessarily strictly adhering to the "X" in AJAX. Since the code loads and executes asynchronously, it is difficult to unit test during the build process. So I have been looking into Javascript testing frameworks that can 1) run headless, i.e. not require a browser; 2) not require jQuery or other framework that supplies DOM access; 3) can test code asynchronously; 4) is compatible with Maven; 5) provides Mock capabilities.

Some candidates were Screw-Unit, jsUnit, QUnit, JSpec, YUI Test, DOH, and Jasmine. For one reason or another they started to drop off the list and that left me with Jasmine. It took a little while to get everything installed correctly into my dev environment and getting Maven configured corectly, but once that was done, it seemed like it would be smooth sailing to test some new code I was writing.

Interestingly, when I had Firebug activated on FF 4.x, I would get a SyntaxError when trying to eval() a regular expression string. I figured I could catch that error in a Jasmine test before it even got to a browser session. Unfortunately, no - Jasmine's Javascript engine does not generate an error when executing eval() on the same string that I sent to the browser. I had been counting on it trapping the error so I could return something informative to the caller, but it looks like I will have to try something else...

So much for trapping and throwing errors in Javascript during unit testing...
SIGH!

No comments:

Post a Comment