Skip to content

Reimplement tests from #5142 #5965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions packages/react-router-dom/modules/__tests__/NavLink-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import ReactDOM from "react-dom";
import MemoryRouter from "react-router/MemoryRouter";
import NavLink from "../NavLink";
import withRouter from "../withRouter";

describe("NavLink", () => {
const node = document.createElement("div");
Expand Down Expand Up @@ -91,6 +92,27 @@ describe("NavLink", () => {
const a = node.getElementsByTagName("a")[0];
expect(a.className).toEqual("active");
});

it("renders child components that use withRouter", () => {
class WrappedComponent extends React.Component {
render() {
return null;
}
}
const Component = withRouter(WrappedComponent);

let ref;
ReactDOM.render(
<MemoryRouter initialEntries={["/pizza"]}>
<NavLink to="/pizza">
<Component wrappedComponentRef={r => (ref = r)} />
</NavLink>
</MemoryRouter>,
node
);

expect(ref instanceof WrappedComponent).toBe(true);
});
});

describe("When a <NavLink> is not active", () => {
Expand Down Expand Up @@ -160,6 +182,27 @@ describe("NavLink", () => {
const a = node.getElementsByTagName("a")[0];
expect(a.getAttribute("aria-current")).toBeNull();
});

it("renders child components that use withRouter", () => {
class WrappedComponent extends React.Component {
render() {
return null;
}
}
const Component = withRouter(WrappedComponent);

let ref;
ReactDOM.render(
<MemoryRouter initialEntries={["/pizza"]}>
<NavLink exact to="/salad">
<Component wrappedComponentRef={r => (ref = r)} />
</NavLink>
</MemoryRouter>,
node
);

expect(ref instanceof WrappedComponent).toBe(true);
});
});

describe("isActive", () => {
Expand Down