All files / src/testHelpers renderWithRouter.tsx

100% Statements 3/3
100% Branches 3/3
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                                  23x 25x   23x                
import { ReactElement, ReactNode } from 'react';
import { Router } from 'react-router-dom';
import { createMemoryHistory, History, InitialEntry } from 'history';
// eslint-disable-next-line import/no-extraneous-dependencies
import { render } from '@testing-library/react';
 
export default (
  ui: ReactElement,
  {
    route = '/',
    history = createMemoryHistory({ initialEntries: [route] }),
  }: {
    route?: InitialEntry;
    history?: History<unknown>;
  } = {}
) => {
  // eslint-disable-next-line react/prop-types
  const Wrapper = ({ children }: { children: ReactNode }) => (
    <Router history={history}>{children}</Router>
  );
  return {
    ...render(ui, { wrapper: Wrapper }),
    // adding `history` to the returned utilities to allow us
    // to reference it in our tests (just try to avoid using
    // this to test implementation details).
    history,
  };
};