import React from 'react';
import { Provider } from 'react-redux';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import { store } from './store';
import Routes from './router/router';
const App: React.FC<RouteComponentProps> = () => {
return (
<Provider store={store}>
<Routes />
</Provider>
);
};
export default withRouter(App);
function renderWithRouterAndStore(
ui,
{ route = '/', history = createMemoryHistory({ initialEntries: [route] }) } = {}
) {
const Wrapper = ({ children }) => {
return (
<Provider store={store}>
<IntlProvider locale="en">
<MemoryRouter initialEntries={[route]}>
<Route path="/login">{children}</Route>
</MemoryRouter>
</IntlProvider>
</Provider>
);
};
return {
...render(ui, { wrapper: Wrapper }),
history,
};
}
I have Login Component, when i submit the form and if the login is successfully, it navigates to '/'.
I am using this.props.history.push('/')
But my test case fail, Cannot read property 'push' of undefined
How to test a React component with RouteComponentProps?