Refactor JavaScript test code