Skip to content

Commit 0cfca57

Browse files
authored
reimplement tests from remix-run#5142
1 parent e5d8c66 commit 0cfca57

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

packages/react-router-dom/modules/__tests__/NavLink-test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import ReactDOM from "react-dom";
33
import MemoryRouter from "react-router/MemoryRouter";
44
import NavLink from "../NavLink";
5+
import withRouter from "../withRouter";
56

67
describe("NavLink", () => {
78
const node = document.createElement("div");
@@ -91,6 +92,27 @@ describe("NavLink", () => {
9192
const a = node.getElementsByTagName("a")[0];
9293
expect(a.className).toEqual("active");
9394
});
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+
});
94116
});
95117

96118
describe("When a <NavLink> is not active", () => {
@@ -160,6 +182,27 @@ describe("NavLink", () => {
160182
const a = node.getElementsByTagName("a")[0];
161183
expect(a.getAttribute("aria-current")).toBeNull();
162184
});
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+
});
163206
});
164207

165208
describe("isActive", () => {

0 commit comments

Comments
 (0)