Instantly share code, notes, and snippets.

Embed
What would you like to do?
react + redux + react-router + Typescript
import * as React from "react";
import { createStore } from "redux";
import { mount } from "enzyme";
import { MemoryRouter, Route } from "react-router";
import { Provider } from "react-redux";
export const mountContainerWithRouter = (
state: State = empty(),
container: JSX.Element,
pathname: string,
search: string,
pathToMatch: string = "/",
initialEntries: string[] = [pathname + search],
initialIndex: number = 0,
actionInterceptor?: (action: Action) => void
) => {
const reduxStore = createStore(
s => s,
state,
createTestMiddleware(actionInterceptor)
);
return mount(
<MemoryRouter initialEntries={initialEntries} initialIndex={initialIndex}>
<Provider store={reduxStore}>
<Route path={pathToMatch} render={() => container} />
</Provider>
</MemoryRouter>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment