Skip to content

Commit

Permalink
added code coverage for new errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bandhan-majumder authored Nov 29, 2024
1 parent de093f7 commit 557eafb
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/utils/errorHandler.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 557eafb

Please sign in to comment.