Refactor karma tests