ErrorContainer.test.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import { ErrorContainer, ErrorContainerProps } from './ErrorContainer';
  4. describe('ErrorContainer', () => {
  5. it('should render component and show message', () => {
  6. const props: ErrorContainerProps = {
  7. queryError: {
  8. data: {
  9. message: 'Error data message',
  10. error: 'Error data content',
  11. },
  12. message: 'Error message',
  13. status: 500,
  14. statusText: 'Error status text',
  15. refId: 'A',
  16. },
  17. };
  18. render(<ErrorContainer {...props} />);
  19. const alertEl = screen.getByRole('alert');
  20. expect(alertEl).toBeInTheDocument();
  21. expect(alertEl).toHaveTextContent(/query error/i);
  22. expect(alertEl).toHaveTextContent('Error message');
  23. });
  24. it('should render component and show message if message is in data only', () => {
  25. const props: ErrorContainerProps = {
  26. queryError: {
  27. data: {
  28. message: 'Error data message',
  29. error: 'Error data content',
  30. },
  31. status: 500,
  32. statusText: 'Error status text',
  33. refId: 'A',
  34. },
  35. };
  36. render(<ErrorContainer {...props} />);
  37. const alertEl = screen.getByRole('alert');
  38. expect(alertEl).toBeInTheDocument();
  39. expect(alertEl).toHaveTextContent(/query error/i);
  40. expect(alertEl).toHaveTextContent('Error data message');
  41. });
  42. it('should have hidden unknown error if prop is not passed in', () => {
  43. const props: ErrorContainerProps = {};
  44. render(<ErrorContainer {...props} />);
  45. const alertEl = screen.getByRole('alert', { hidden: true });
  46. expect(alertEl).toBeInTheDocument();
  47. expect(alertEl).toHaveTextContent('Unknown error');
  48. });
  49. });