Layout.spec.tsx 968 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { render } from '@testing-library/react';
  2. import Layout from '../../layout/Layout';
  3. import { MuiThemeProvider } from '@material-ui/core/styles';
  4. import { theme } from '../../../styles/theme';
  5. import { vi } from 'vitest';
  6. vi.mock('react-i18next', () => {
  7. return {
  8. useTranslation: () => ({
  9. t: (key: any) => key,
  10. }),
  11. };
  12. });
  13. vi.mock('react-router-dom', () => {
  14. return {
  15. useHistory: () => ({
  16. push: vi.fn(),
  17. }),
  18. useLocation: () => ({
  19. hash: '',
  20. pathname: '/use-location-mock',
  21. search: '',
  22. state: undefined,
  23. }),
  24. };
  25. });
  26. vi.mock('../../layout/GlobalEffect', () => {
  27. return {
  28. default: () => {
  29. return <div role="global">{}</div>;
  30. },
  31. };
  32. });
  33. describe('Test Layout', () => {
  34. it('Test Render', () => {
  35. const res = render(
  36. <MuiThemeProvider theme={theme}>
  37. <Layout />
  38. </MuiThemeProvider>
  39. );
  40. expect(res.getAllByRole('global').length).toEqual(1);
  41. });
  42. });