Refactoring to improve testing of javascript