import React, { Fragment } from 'react';
import { render, RenderResult } from '@testing-library/react';
import { ThemeProvider } from '~/styles';

const customRender = (node: React.ReactElement<any>, ...opts: any[]): RenderResult => {
  const { rerender, ...result } = render(
    <ThemeProvider>{node}</ThemeProvider>,
    ...opts
  );

  const customRerender = (rerenderNode: React.ReactElement<any>) => {
    return rerender(<Fragment>{rerenderNode}</Fragment>);
  };

  return { rerender: customRerender, ...result };
};

export * from '@testing-library/react';
export { customRender as render };