Add sinon.js to testing suite for better spying, mocking and stubbing

Fixes #847
Test code clean up
Leverage spies and stubs in tests