Skip to content

Commit

Permalink
updated errorHandler.test.tsx with few more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bandhan-majumder committed Dec 12, 2024
1 parent 24d4b7b commit b1ef59b
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/utils/errorHandler.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,43 @@ describe('Test if errorHandler is working properly', () => {
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);
it('should handle error messages with different cases', () => {
errorHandler(t, new Error('VALUE IS NOT A VALID PHONE NUMBER'));
expect(toast.error).toHaveBeenCalledWith(tErrors('invalidPhoneNumber'));

errorHandler(t, new Error('This Value Does Not Exist in "EducationGrade"'));
expect(toast.error).toHaveBeenCalledWith(tErrors('invalidEducationGrade'));
});

it('should call toast.error with the error message if it is an instance of error but have not matched any error message patterns', () => {
const error = new Error('Bandhan sent an error message');
errorHandler(t, error);
expect(toast.error).toHaveBeenCalledWith(error.message);
});

it('should handle different types for the first parameter while still showing error messages', () => {
errorHandler(undefined, new Error('Some error'));
expect(toast.error).toHaveBeenCalled();

errorHandler(null, new Error('Some error'));
expect(toast.error).toHaveBeenCalled();

errorHandler({}, new Error('Some error'));
expect(toast.error).toHaveBeenCalled();
});

it('should handle non-null but non-Error objects for the error parameter', () => {
errorHandler(t, { message: 'Error message in object' });
expect(toast.error).toHaveBeenCalledWith(
tErrors('unknownError', { msg: { message: 'Error message in object' } }),
);

errorHandler(t, 'Direct error message');
expect(toast.error).toHaveBeenCalledWith(
tErrors('unknownError', { msg: 'Direct error message' }),
);
});

it('should call toast.error with the error message if error object is falsy', () => {
const error = null;
errorHandler(t, error);
Expand Down

0 comments on commit b1ef59b

Please sign in to comment.