Skip to content

Commit 439bf95

Browse files
author
Alexis
committed
test: button renders internal link
1 parent 954bc11 commit 439bf95

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

client/common/ButtonOrLink.test.jsx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import React from 'react';
2-
import { render, screen, fireEvent } from '../test-utils';
2+
import { browserHistory, Route, Router, IndexRoute } from 'react-router';
3+
import { Provider } from 'react-redux';
4+
import configureStore from '../store';
5+
import { render, screen, fireEvent, userEvent, waitFor } from '../test-utils';
36
import ButtonOrLink from './ButtonOrLink';
7+
import routes from '../routes';
48

59
describe('ButtonOrLink', () => {
610
const clickHandler = jest.fn();
@@ -25,8 +29,28 @@ describe('ButtonOrLink', () => {
2529
expect(link).toHaveAttribute('href', 'https://p5js.org');
2630
});
2731

28-
it('can render an internal link with react-router', () => {
29-
render(<ButtonOrLink href="/about">About</ButtonOrLink>);
30-
// TODO: how can this be tested? Needs a router provider?
32+
it('can render an internal link with react-router', async () => {
33+
const store = configureStore();
34+
render(
35+
<Provider store={store}>
36+
<Router
37+
history={browserHistory}
38+
routes={
39+
<Route
40+
path="/"
41+
component={() => <ButtonOrLink href="/about">About</ButtonOrLink>}
42+
/>
43+
}
44+
/>
45+
</Provider>
46+
);
47+
48+
const link = screen.getByText('About');
49+
fireEvent.click(link);
50+
await waitFor(() =>
51+
expect(browserHistory.getCurrentLocation()).toEqual(
52+
expect.objectContaining({ pathname: '/about' })
53+
)
54+
);
3155
});
3256
});

0 commit comments

Comments
 (0)