Skip to content

Instantly share code, notes, and snippets.

@cocodrino
Created July 14, 2021 14:35
Show Gist options
  • Save cocodrino/c3f21e050f760b3e7d344ac387ac94b3 to your computer and use it in GitHub Desktop.
Save cocodrino/c3f21e050f760b3e7d344ac387ac94b3 to your computer and use it in GitHub Desktop.
wrapper for react testing library and redux
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