testHelpers.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React from 'react';
  2. import { MemoryRouter, Route, StaticRouter } from 'react-router-dom';
  3. import { Provider } from 'react-redux';
  4. import { mount } from 'enzyme';
  5. import { act } from 'react-dom/test-utils';
  6. import configureStore from 'redux/store/configureStore';
  7. interface TestRouterWrapperProps {
  8. pathname: string;
  9. urlParams: {
  10. [key: string]: string;
  11. };
  12. }
  13. export const TestRouterWrapper: React.FC<TestRouterWrapperProps> = ({
  14. children,
  15. pathname,
  16. urlParams,
  17. }) => (
  18. <MemoryRouter
  19. initialEntries={[
  20. {
  21. key: 'test',
  22. pathname: Object.keys(urlParams).reduce(
  23. (acc, param) => acc.replace(`:${param}`, urlParams[param]),
  24. pathname
  25. ),
  26. },
  27. ]}
  28. >
  29. <Route path={pathname}>{children}</Route>
  30. </MemoryRouter>
  31. );
  32. export const containerRendersView = (
  33. container: React.ReactElement,
  34. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  35. view: React.FC<any>
  36. ) => {
  37. describe('container', () => {
  38. const store = configureStore();
  39. it('renders view', async () => {
  40. let wrapper = mount(<div />);
  41. await act(async () => {
  42. wrapper = mount(
  43. <Provider store={store}>
  44. <StaticRouter>{container}</StaticRouter>
  45. </Provider>
  46. );
  47. });
  48. expect(wrapper.exists(view)).toBeTruthy();
  49. });
  50. });
  51. };