checkIsResponseError.spec.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { checkIsResponseError } from './checkIsResponseError';
  2. describe('checkIsResponseError', () => {
  3. it('should return true for a valid IResponseError object', () => {
  4. const error = {
  5. error: 'Something went wrong',
  6. message: 'An error occurred',
  7. statusCode: 500,
  8. };
  9. const result = checkIsResponseError(error);
  10. expect(result).toBe(true);
  11. });
  12. it('should return false for null', () => {
  13. const result = checkIsResponseError(null);
  14. expect(result).toBe(false);
  15. });
  16. it('should return false for undefined', () => {
  17. const result = checkIsResponseError(undefined);
  18. expect(result).toBe(false);
  19. });
  20. it('should return false for a non-object value', () => {
  21. const result = checkIsResponseError('This is a string');
  22. expect(result).toBe(false);
  23. });
  24. it('should return false if the object is missing the "error" property', () => {
  25. const error = {
  26. message: 'An error occurred',
  27. statusCode: 500,
  28. };
  29. const result = checkIsResponseError(error);
  30. expect(result).toBe(false);
  31. });
  32. it('should return false if the object is missing the "message" property', () => {
  33. const error = {
  34. error: 'Something went wrong',
  35. statusCode: 500,
  36. };
  37. const result = checkIsResponseError(error);
  38. expect(result).toBe(false);
  39. });
  40. it('should return false if the object is missing the "statusCode" property', () => {
  41. const error = {
  42. error: 'Something went wrong',
  43. message: 'An error occurred',
  44. };
  45. const result = checkIsResponseError(error);
  46. expect(result).toBe(false);
  47. });
  48. });