11import 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' ;
36import ButtonOrLink from './ButtonOrLink' ;
7+ import routes from '../routes' ;
48
59describe ( '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