Skip to content

Commit 42c7017

Browse files
committed
Update bug-report-test.ts to demonstrate href() problem
1 parent 0617758 commit 42c7017

File tree

1 file changed

+48
-23
lines changed

1 file changed

+48
-23
lines changed

integration/bug-report-test.ts

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,52 @@ test.beforeAll(async () => {
6464
// `createFixture` will make an app and run your tests against it.
6565
////////////////////////////////////////////////////////////////////////////
6666
files: {
67+
"app/routes.ts": js`
68+
import { type RouteConfig } from "@react-router/dev/routes";
69+
import { flatRoutes } from "@react-router/fs-routes";
70+
71+
export default flatRoutes() satisfies RouteConfig;
72+
`,
73+
6774
"app/routes/_index.tsx": js`
68-
import { useLoaderData, Link } from "react-router";
75+
import { href } from "react-router";
76+
import type { Route } from "./+types/_index";
6977
7078
export function loader() {
71-
return "pizza";
79+
return { id: "a123" };
7280
}
7381
74-
export default function Index() {
75-
let data = useLoaderData();
82+
export default function Home({ loaderData }: Route.ComponentProps) {
7683
return (
7784
<div>
78-
{data}
79-
<Link to="/burgers">Other Route</Link>
85+
<ul>
86+
<li>
87+
<a href={href("/text/:id.txt", { id: loaderData.id })} id="with-href">
88+
View text file for id {loaderData.id} with href()
89+
</a>
90+
</li>
91+
<li>
92+
<a href={${"`"}/text/\${loaderData.id}.txt${"`"}} id="with-template-string">
93+
View text file for id {loaderData.id} with template string
94+
</a>
95+
</li>
96+
</ul>
8097
</div>
81-
)
98+
);
8299
}
83100
`,
84101

85-
"app/routes/burgers.tsx": js`
86-
export default function Index() {
87-
return <div>cheeseburger</div>;
102+
"app/routes/text.$id[.txt].ts": js`
103+
import type { Route } from "./+types/text.$id[.txt]";
104+
105+
export async function loader({ params }: Route.LoaderArgs) {
106+
const text = "The text file content for id: " + params.id;
107+
return new Response(text, {
108+
status: 200,
109+
headers: {
110+
"Content-Type": "text/plain",
111+
},
112+
});
88113
}
89114
`,
90115
},
@@ -103,22 +128,22 @@ test.afterAll(() => {
103128
// add a good description for what you expect React Router to do 👇🏽
104129
////////////////////////////////////////////////////////////////////////////////
105130

106-
test("[description of what you expect it to do]", async ({ page }) => {
131+
test("link from template string is correct", async ({ page }) => {
107132
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`
113133
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);
134+
await app.clickElement("a#with-template-string");
135+
await page.waitForURL("**/text/**");
136+
let content = await page.content();
137+
await expect(content).toContain("The text file content for id:");
138+
});
120139

121-
// Go check out the other tests to see what else you can do.
140+
test("link from href is correct", async ({ page }) => {
141+
let app = new PlaywrightFixture(appFixture, page);
142+
await app.goto("/");
143+
await app.clickElement("a#with-href");
144+
await page.waitForURL("**/text/**");
145+
let content = await page.content();
146+
await expect(content).toContain("The text file content for id:");
122147
});
123148

124149
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)