Refactoring the code by Jest