Last active
August 13, 2021 20:26
-
-
Save bonnie/180532a9b0f0110c23916b17400c3799 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { EnhancedStore } from "@reduxjs/toolkit"; // for redux-toolkit | |
// import { Store } from 'redux' // for non-toolkit | |
import { | |
render as rtlRender, | |
RenderOptions, | |
RenderResult, | |
} from "@testing-library/react"; | |
import { ReactElement, ReactNode } from "react"; | |
import { Provider } from "react-redux"; | |
import { configureStoreWithMiddlewares, RootState } from "../store"; | |
type ReduxRenderOptions = { | |
preloadedState?: RootState; | |
store?: EnhancedStore; // for redux-toolkit | |
// store?: Store // for non-toolkit | |
renderOptions?: Omit<RenderOptions, "wrapper">; | |
}; | |
function render( | |
ui: ReactElement, | |
{ | |
preloadedState = {}, | |
store = configureStoreWithMiddlewares(preloadedState), | |
...renderOptions | |
}: ReduxRenderOptions = {} | |
): RenderResult { | |
function Wrapper({ children }: { children?: ReactNode }): ReactElement { | |
return <Provider store={store}>{children}</Provider>; | |
} | |
return rtlRender(ui, { wrapper: Wrapper, ...renderOptions }); | |
} | |
// re-export everything | |
export * from "@testing-library/react"; | |
// override render method | |
export { render }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment