@@ -64,27 +64,22 @@ test.beforeAll(async () => {
64
64
// `createFixture` will make an app and run your tests against it.
65
65
////////////////////////////////////////////////////////////////////////////
66
66
files : {
67
- "app/routes/_index .tsx" : js `
68
- import { useLoaderData, Link } from "react-router";
67
+ "app/routes/use-params.$id .tsx" : js `
68
+ import { useParams } from "react-router";
69
69
70
- export function loader() {
71
- return "pizza";
72
- }
73
-
74
- export default function Index() {
75
- let data = useLoaderData();
76
- return (
77
- <div>
78
- {data}
79
- <Link to="/burgers">Other Route</Link>
80
- </div>
81
- )
70
+ export default function ItemPage() {
71
+ let params = useParams();
72
+ return <div data-testid="item-id">Item ID: {params.id}</div>;
82
73
}
83
74
` ,
84
75
85
- "app/routes/burgers.tsx" : js `
86
- export default function Index() {
87
- return <div>cheeseburger</div>;
76
+ "app/routes/match-path.$id.tsx" : js `
77
+ import { matchPath, useLocation } from "react-router";
78
+
79
+ export default function ItemPage() {
80
+ const location = useLocation()
81
+ const match = matchPath({ path: '/match-path/:id' }, location.pathname)
82
+ return <div data-testid="item-id">Item ID: {match.params.id}</div>;
88
83
}
89
84
` ,
90
85
} ,
@@ -103,22 +98,24 @@ test.afterAll(() => {
103
98
// add a good description for what you expect React Router to do 👇🏽
104
99
////////////////////////////////////////////////////////////////////////////////
105
100
106
- test ( "[description of what you expect it to do]" , async ( { page } ) => {
101
+ test ( "useParams should not decode param containing double-encoded forward slash" , async ( {
102
+ page,
103
+ } ) => {
107
104
let app = new PlaywrightFixture ( appFixture , page ) ;
108
- // You can test any request your app might get using `fixture`.
109
- let response = await fixture . requestDocument ( "/" ) ;
110
- expect ( await response . text ( ) ) . toMatch ( "pizza" ) ;
111
-
112
- // If you need to test interactivity use the `app`
113
- await app . goto ( "/" ) ;
114
- await app . clickLink ( "/burgers" ) ;
115
- await page . waitForSelector ( "text=cheeseburger" ) ;
116
-
117
- // If you're not sure what's going on, you can "poke" the app, it'll
118
- // automatically open up in your browser for 20 seconds, so be quick!
119
- // await app.poke(20);
105
+ const encodedId = encodeURIComponent ( encodeURIComponent ( "beforeslash/afterslash@" ) ) ;
106
+ await app . goto ( `/use-params/${ encodedId } ` ) ;
107
+ let el = page . locator ( "[data-testid='item-id']" ) ;
108
+ await expect ( el ) . toHaveText ( `Item ID: ${ encodedId } ` ) ;
109
+ } ) ;
120
110
121
- // Go check out the other tests to see what else you can do.
111
+ test ( "matchPath should not decode param containing double-encoded forward slash" , async ( {
112
+ page,
113
+ } ) => {
114
+ let app = new PlaywrightFixture ( appFixture , page ) ;
115
+ const encodedId = encodeURIComponent ( encodeURIComponent ( "beforeslash/afterslash@" ) ) ;
116
+ await app . goto ( `/match-path/${ encodedId } ` ) ;
117
+ let el = page . locator ( "[data-testid='item-id']" ) ;
118
+ await expect ( el ) . toHaveText ( `Item ID: ${ encodedId } ` ) ;
122
119
} ) ;
123
120
124
121
////////////////////////////////////////////////////////////////////////////////
0 commit comments