checkIsResponseError.spec.js 2.0 KB

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