/** @jsx jsx */ import { jsx } from "@emotion/react"; import { PropsWithChildren } from "react"; import { render } from "@testing-library/react"; import type { RenderOptions } from "@testing-library/react"; import { Provider } from "react-redux"; import type { AppStore, RootState } from "../store"; import { setupStore } from "../store"; interface ExtendedRenderOptions extends Omit { preloadedState?: Partial store?: AppStore } export function renderWithProviders( ui: React.ReactElement, extendedRenderOptions: ExtendedRenderOptions = {} ) { const { preloadedState = {}, // Automatically create a store instance if no store was passed in store = setupStore(preloadedState), ...renderOptions } = extendedRenderOptions; const Wrapper = ({ children }: PropsWithChildren) => ( {children} ); // Return an object with the store and all of RTL"s query functions return { store, ...render(ui, { wrapper: Wrapper, ...renderOptions }) }; }