diff --git a/src/utils/errorHandler.test.tsx b/src/utils/errorHandler.test.tsx index 45f46e6389..a25ec63d2c 100644 --- a/src/utils/errorHandler.test.tsx +++ b/src/utils/errorHandler.test.tsx @@ -21,6 +21,43 @@ describe('Test if errorHandler is working properly', () => { expect(toast.error).toHaveBeenCalledWith(tErrors('talawaApiUnavailable')); }); + it('should call toast.error with the correct message if error message contains this substring "Value is not a valid phone number"', () => { + const error = new Error('This value is not a valid phone number'); + errorHandler(t, error); + + expect(toast.error).toHaveBeenCalledWith(tErrors('invalidPhoneNumber')); + }); + + it('should call toast.error with the correct message if error message contains this substring "Value does not exist in "EducationGrade""', () => { + const error = new Error('This value does not exist in "EducationGrade"'); + errorHandler(t, error); + + expect(toast.error).toHaveBeenCalledWith(tErrors('invalidEducationGrade')); + }); + + it('should call toast.error with the correct message if error message contains this substring "Value does not exist in "EmploymentStatus"', () => { + const error = new Error('This value does not exist in "EmploymentStatus"'); + errorHandler(t, error); + + expect(toast.error).toHaveBeenCalledWith( + tErrors('invalidEmploymentStatus'), + ); + }); + + it('should call toast.error with the correct message if error message contains this substring "Value does not exist in "MaritalStatus"', () => { + const error = new Error('This value does not exist in "MaritalStatus"'); + errorHandler(t, error); + + expect(toast.error).toHaveBeenCalledWith(tErrors('invalidMaritalStatus')); + }); + + it('should call toast.error with the correct message if error message contains this substring "status code 400"', () => { + const error = new Error('Server responded with status code 400'); + errorHandler(t, error); + + expect(toast.error).toHaveBeenCalledWith(tErrors('error400')); + }); + it('should call toast.error with the error message if it is not "Failed to fetch"', () => { const error = new Error('Some other error message'); errorHandler(t, error);