2
0

Layout.spec.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { render, unmountComponentAtNode } from 'react-dom';
  2. import { act } from 'react-dom/test-utils';
  3. import Layout from '../../layout/Layout';
  4. let container: any = null;
  5. jest.mock('react-i18next', () => ({
  6. useTranslation: () => ({
  7. t: (key: any) => key,
  8. }),
  9. }));
  10. jest.mock('react-router-dom', () => ({
  11. useHistory: () => ({
  12. push: jest.fn(),
  13. }),
  14. useLocation: () => ({
  15. hash: '',
  16. pathname: '/use-location-mock',
  17. search: '',
  18. state: undefined,
  19. }),
  20. }));
  21. jest.mock('../../layout/GlobalEffect', () => {
  22. return () => {
  23. return <div id="global">{}</div>;
  24. };
  25. });
  26. describe('Test Layout', () => {
  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 Render', () => {
  37. act(() => {
  38. render(<Layout />, container);
  39. });
  40. expect(container.querySelectorAll('#global').length).toEqual(1);
  41. });
  42. });