home

Introducing jstub

27 Sep 2010

After playing with a skeleton yesterday, I spent a couple hours and rolled out my own javascript stubbing framework. I happen to have a rapidly growing amount of javascript code that needs testing, so I figured it'd make a nice testbed. The github project has fairly comprehensive documentation (the readme and the tests).

You might be asking why another framework? The truth is that the few that I had either looked at or was using just didn't do it for me. Largely, they were more full blown mocking frameworks, when the reality is that, right or wrong, the way I write my javascript and the way I test it, simple stubs is just a better fit.

Also, I had been using mockjax to mock out my ajax calls, but it wasn't doing it for me. First, I found it painful to specify the expected posted data (something critically important). I also wanted the stub to work synchronously to greatly increase the readability of my test. A coworker and I had a disagreement about whether this was good. His belief was that making a synchronous stub out of an asynchronous call is diverging too far away from the actual code. My belief is that the unreliable nature of asynchronous code means that it should be interchange with synchronous code - if you have code that relies on being execute either before or after a async call, that must be explicitly coded for.

Check out the source code on github at: http://github.com/karlseguin/jstub and let me know what you think.

blog comments powered by Disqus