Skip to content

Commit 01aa443

Browse files
author
Alexis
committed
test: clean up history
1 parent c71b6f8 commit 01aa443

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

client/common/ButtonOrLink.test.jsx

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import React from 'react';
2-
import { browserHistory, Route, Router } from 'react-router';
3-
import { Provider } from 'react-redux';
4-
import configureStore from '../store';
5-
import { render, screen, fireEvent, waitFor } from '../test-utils';
2+
import { render, screen, fireEvent, waitFor, history } from '../test-utils';
63
import ButtonOrLink from './ButtonOrLink';
74

85
describe('ButtonOrLink', () => {
@@ -29,27 +26,11 @@ describe('ButtonOrLink', () => {
2926
});
3027

3128
it('can render an internal link with react-router', async () => {
32-
const store = configureStore();
33-
render(
34-
<Provider store={store}>
35-
<Router
36-
history={browserHistory}
37-
routes={
38-
<Route
39-
path="/"
40-
component={() => <ButtonOrLink href="/about">About</ButtonOrLink>}
41-
/>
42-
}
43-
/>
44-
</Provider>
45-
);
29+
render(<ButtonOrLink href="/about">About</ButtonOrLink>);
4630

4731
const link = screen.getByText('About');
4832
fireEvent.click(link);
49-
await waitFor(() =>
50-
expect(browserHistory.getCurrentLocation()).toEqual(
51-
expect.objectContaining({ pathname: '/about' })
52-
)
53-
);
33+
34+
await waitFor(() => expect(history.location.pathname).toEqual('/about'));
5435
});
5536
});

client/test-utils.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ import PropTypes from 'prop-types';
1717
import { createStore } from 'redux';
1818
import { Provider } from 'react-redux';
1919
import { Router } from 'react-router-dom';
20+
import { createMemoryHistory } from 'history';
2021
import { I18nextProvider } from 'react-i18next';
2122
import { ThemeProvider as StyledThemeProvider } from 'styled-components';
2223

23-
import browserHistory from './browserHistory';
2424
import i18n from './i18n-test';
2525
import rootReducer from './reducers';
2626
import ThemeProvider from './modules/App/components/ThemeProvider';
2727
import theme, { Theme } from './theme';
2828

29+
export const history = createMemoryHistory();
30+
2931
// re-export everything
3032
// eslint-disable-next-line import/no-extraneous-dependencies
3133
export * from '@testing-library/react';
@@ -34,7 +36,7 @@ const Providers = ({ children }) => (
3436
// eslint-disable-next-line react/jsx-filename-extension
3537
<StyledThemeProvider theme={{ ...theme[Theme.light] }}>
3638
<I18nextProvider i18n={i18n}>
37-
<Router history={browserHistory}>{children}</Router>
39+
<Router history={history}>{children}</Router>
3840
</I18nextProvider>
3941
</StyledThemeProvider>
4042
);
@@ -56,7 +58,7 @@ function reduxRender(
5658
<I18nextProvider i18n={i18n}>
5759
<Provider store={store}>
5860
<ThemeProvider>
59-
<Router history={browserHistory}>{children}</Router>
61+
<Router history={history}>{children}</Router>
6062
</ThemeProvider>
6163
</Provider>
6264
</I18nextProvider>

0 commit comments

Comments
 (0)