Created
July 14, 2021 14:35
-
-
Save cocodrino/c3f21e050f760b3e7d344ac387ac94b3 to your computer and use it in GitHub Desktop.
wrapper for react testing library and redux
This file contains 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 { configureStore, Store } from '@reduxjs/toolkit'; | |
import React, { ComponentType, ReactElement } from 'react'; | |
import { Provider } from 'react-redux'; | |
import { createMemoryHistory } from 'history'; | |
import { Router } from 'react-router'; | |
import { reducer } from '../state/store'; | |
export const makeStore = (): Store => configureStore({ reducer }); | |
const history = createMemoryHistory(); | |
const wrapComponent = ( | |
Component: ComponentType, | |
store: Store | null = null, | |
props = {} | |
): ReactElement => ( | |
<Provider store={store || makeStore()}> | |
<Router history={history}> | |
<Component {...props} /> | |
</Router> | |
</Provider> | |
); | |
export default wrapComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment