Added unit tests

I started work on integrating some unit tests using QUnit, in the long term this will require changes to the code base to make it more testable, this will of course potentially break backwards compatibility so the sooner the better so the API can stabilise.