Skip to content

Commit 818f8e0

Browse files
committed
Add unit test
1 parent 488e330 commit 818f8e0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as React from "react";
2+
3+
import { render, screen } from "@testing-library/react";
4+
import { createMemoryRouter, useParams } from "react-router";
5+
import { RouterProvider } from "react-router/dom";
6+
7+
describe("react-router/dom", () => {
8+
function ShowParams() {
9+
return <pre data-testid="params">{JSON.stringify(useParams())}</pre>;
10+
}
11+
12+
describe("Does not bundle react-router causing duplicate context issues", () => {
13+
it("with route provider shows the url params", async () => {
14+
const router = createMemoryRouter(
15+
[
16+
{
17+
path: "/blog/:slug",
18+
element: <ShowParams />,
19+
},
20+
],
21+
{
22+
initialEntries: ["/blog/react-router"],
23+
}
24+
);
25+
26+
// When react-router was bundled in CJS scenarios, this `react-router/dom`
27+
// version of `RouterProvider` caused duplicate contexts and we would not
28+
// find the param values
29+
render(<RouterProvider router={router} />);
30+
31+
expect(await screen.findByTestId("params")).toMatchInlineSnapshot(`
32+
<pre
33+
data-testid="params"
34+
>
35+
{"slug":"react-router"}
36+
</pre>
37+
`);
38+
});
39+
});
40+
});

0 commit comments

Comments
 (0)