Skip to content

Commit

Permalink
Add test for matchRoutes returning the same object
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Sep 10, 2021
1 parent 1ecefcf commit 0ae536f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.

This file was deleted.

This file was deleted.

23 changes: 23 additions & 0 deletions packages/react-router/__tests__/matchRoutes-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from "react";
import { Outlet, matchRoutes } from "react-router";

describe("matchRoutes", () => {
it("returns the same route object on match.route as the one that was passed in", () => {
let userProfileRoute = { path: ":id", element: <h1>user profile </h1> };
let usersRoute = {
path: "/users",
element: (
<h1>
users <Outlet />
</h1>
),
children: [userProfileRoute]
};

let matches = matchRoutes([usersRoute], "/users/mj")!;

expect(matches).not.toBeNull();
expect(matches[0].route).toBe(usersRoute);
expect(matches[1].route).toBe(userProfileRoute);
});
});
12 changes: 6 additions & 6 deletions packages/react-router/__tests__/useOutlet-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ describe("useOutlet", () => {
return useOutlet();
}

function Profile() {
return <p>Profile</p>;
}

let renderer = createTestRenderer(
<Router initialEntries={["/users/profile"]}>
<Routes>
<Route path="users" element={<Users />}>
<Route path="profile" element={<Profile />} />
<Route path="profile" element={<h1>Profile</h1>} />
</Route>
</Routes>
</Router>
);

expect(renderer.toJSON()).toMatchSnapshot();
expect(renderer.toJSON()).toMatchInlineSnapshot(`
<h1>
Profile
</h1>
`);
});
});
});

0 comments on commit 0ae536f

Please sign in to comment.