1
1
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' ;
3
6
import ButtonOrLink from './ButtonOrLink' ;
7
+ import routes from '../routes' ;
4
8
5
9
describe ( 'ButtonOrLink' , ( ) => {
6
10
const clickHandler = jest . fn ( ) ;
@@ -25,8 +29,28 @@ describe('ButtonOrLink', () => {
25
29
expect ( link ) . toHaveAttribute ( 'href' , 'https://p5js.org' ) ;
26
30
} ) ;
27
31
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
+ ) ;
31
55
} ) ;
32
56
} ) ;
0 commit comments