Skip to content

test: fetcher.load returns 404 for route not "discovered" yet. #13117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
- mtendekuyokwa19
- mtliendo
- ned-park
- nicksrandall
- nikeee
- nilubisan
- Nismit
Expand Down
39 changes: 25 additions & 14 deletions integration/bug-report-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ let appFixture: AppFixture;
// Now try running this test:
//
// ```
// pnpm test:integration bug-report --project chromium
// ```
// pnpm test:integration bug-report --project chromium ```
//
// You can add `--watch` to the end to have it re-run on file changes:
//
Expand All @@ -64,27 +63,36 @@ test.beforeAll(async () => {
// `createFixture` will make an app and run your tests against it.
////////////////////////////////////////////////////////////////////////////
files: {
"app/routes/_index.tsx": js`
import { useLoaderData, Link } from "react-router";

export function loader() {
return "pizza";
"api/auth/me": js`
export const loader = async () => {
await new Promise((resolve) => setTimeout(resolve, 500));
return { user: { name: "Michael" } };
}
`,
"app/routes/_index.tsx": js`
import { Link } from "react-router";

export default function Index() {
let data = useLoaderData();
return (
<div>
{data}
<Link to="/burgers">Other Route</Link>
</div>
)
}
`,

"app/routes/burgers.tsx": js`
import * as React from "react";
import { useFetcher } from "react-router";

export default function Index() {
return <div>cheeseburger</div>;
const fetcher = useFetcher();
React.useEffect(() => {
if (fetcher.state === "idle") {
fetcher.load("/api/auth/me");
}
}, []);
return (<h1>{fetcher.data ? fetcher.data.user.name : "loading..."}</h1>);
}
`,
},
Expand All @@ -103,16 +111,19 @@ test.afterAll(() => {
// add a good description for what you expect React Router to do 👇🏽
////////////////////////////////////////////////////////////////////////////////

test("[description of what you expect it to do]", async ({ page }) => {
test("I expect this page to not 404", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
// You can test any request your app might get using `fixture`.
let response = await fixture.requestDocument("/");
expect(await response.text()).toMatch("pizza");
// let response = await fixture.requestDocument("/");

// If you need to test interactivity use the `app`
await app.goto("/");
await app.clickLink("/burgers");
await page.waitForSelector("text=cheeseburger");

// expect that the page will not 404
expect(await page.textContent("h1")).not.toBe("404 Not Found");

// await page.waitForSelector("text=Michael");

// If you're not sure what's going on, you can "poke" the app, it'll
// automatically open up in your browser for 20 seconds, so be quick!
Expand Down