File tree 1 file changed +40
-0
lines changed
packages/react-router/__tests__/dom
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments