// See https://redux.js.org/usage/writing-tests#setting-up-a-reusable-test-render-function for more information import React, { PropsWithChildren } from "react"; import { Provider } from "react-redux"; import { configureStore } from "@reduxjs/toolkit"; // eslint-disable-next-line import/no-extraneous-dependencies import { RenderOptions, render } from "@testing-library/react"; import { AppStore, RootState, rootReducer } from "./src/store"; import { SocketProvider } from "#/context/socket"; const setupStore = (preloadedState?: Partial): AppStore => configureStore({ reducer: rootReducer, preloadedState, }); // This type interface extends the default options for render from RTL, as well // as allows the user to specify other things such as initialState, store. interface ExtendedRenderOptions extends Omit { preloadedState?: Partial; store?: AppStore; } // Export our own customized renderWithProviders function that creates a new Redux store and renders a // Note that this creates a separate Redux store instance for every test, rather than reusing the same store instance and resetting its state export function renderWithProviders( ui: React.ReactElement, { preloadedState = {}, // Automatically create a store instance if no store was passed in store = setupStore(preloadedState), ...renderOptions }: ExtendedRenderOptions = {}, ) { function Wrapper({ children }: PropsWithChildren): JSX.Element { return ( {children} ); } return { store, ...render(ui, { wrapper: Wrapper, ...renderOptions }) }; }