@@ -2,6 +2,7 @@ import React from "react";
2
2
import ReactDOM from "react-dom" ;
3
3
import MemoryRouter from "react-router/MemoryRouter" ;
4
4
import NavLink from "../NavLink" ;
5
+ import withRouter from "../withRouter" ;
5
6
6
7
describe ( "NavLink" , ( ) => {
7
8
const node = document . createElement ( "div" ) ;
@@ -91,6 +92,27 @@ describe("NavLink", () => {
91
92
const a = node . getElementsByTagName ( "a" ) [ 0 ] ;
92
93
expect ( a . className ) . toEqual ( "active" ) ;
93
94
} ) ;
95
+
96
+ it ( "renders child components that use withRouter" , ( ) => {
97
+ class WrappedComponent extends React . Component {
98
+ render ( ) {
99
+ return null ;
100
+ }
101
+ }
102
+ const Component = withRouter ( WrappedComponent ) ;
103
+
104
+ let ref ;
105
+ ReactDOM . render (
106
+ < MemoryRouter initialEntries = { [ "/pizza" ] } >
107
+ < NavLink to = "/pizza" >
108
+ < Component wrappedComponentRef = { r => ( ref = r ) } />
109
+ </ NavLink >
110
+ </ MemoryRouter > ,
111
+ node
112
+ ) ;
113
+
114
+ expect ( ref instanceof WrappedComponent ) . toBe ( true ) ;
115
+ } ) ;
94
116
} ) ;
95
117
96
118
describe ( "When a <NavLink> is not active" , ( ) => {
@@ -160,6 +182,27 @@ describe("NavLink", () => {
160
182
const a = node . getElementsByTagName ( "a" ) [ 0 ] ;
161
183
expect ( a . getAttribute ( "aria-current" ) ) . toBeNull ( ) ;
162
184
} ) ;
185
+
186
+ it ( "renders child components that use withRouter" , ( ) => {
187
+ class WrappedComponent extends React . Component {
188
+ render ( ) {
189
+ return null ;
190
+ }
191
+ }
192
+ const Component = withRouter ( WrappedComponent ) ;
193
+
194
+ let ref ;
195
+ ReactDOM . render (
196
+ < MemoryRouter initialEntries = { [ "/pizza" ] } >
197
+ < NavLink exact to = "/salad" >
198
+ < Component wrappedComponentRef = { r => ( ref = r ) } />
199
+ </ NavLink >
200
+ </ MemoryRouter > ,
201
+ node
202
+ ) ;
203
+
204
+ expect ( ref instanceof WrappedComponent ) . toBe ( true ) ;
205
+ } ) ;
163
206
} ) ;
164
207
165
208
describe ( "isActive" , ( ) => {
0 commit comments