Status.spec.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { render, unmountComponentAtNode } from 'react-dom';
  2. import { act } from 'react-dom/test-utils';
  3. import Status from '../../status/Status';
  4. import { StatusEnum } from '../../status/Types';
  5. let container: any = null;
  6. jest.mock('react-i18next', () => {
  7. return {
  8. useTranslation: () => {
  9. return {
  10. t: name => {
  11. return {
  12. loaded: 'loaded',
  13. unloaded: 'unloaded',
  14. error: 'error',
  15. };
  16. },
  17. };
  18. },
  19. };
  20. });
  21. jest.mock('@material-ui/core/Typography', () => {
  22. return props => {
  23. return <div className="label">{props.children}</div>;
  24. };
  25. });
  26. describe('Test Status', () => {
  27. beforeEach(() => {
  28. container = document.createElement('div');
  29. document.body.appendChild(container);
  30. });
  31. afterEach(() => {
  32. unmountComponentAtNode(container);
  33. container.remove();
  34. container = null;
  35. });
  36. it('Test props status', () => {
  37. act(() => {
  38. render(<Status status={StatusEnum.loaded} />, container);
  39. });
  40. expect(container.querySelector('.label').textContent).toEqual('loaded');
  41. act(() => {
  42. render(<Status status={StatusEnum.unloaded} />, container);
  43. });
  44. expect(container.querySelector('.label').textContent).toEqual('unloaded');
  45. });
  46. });