Skip to content

Commit a9848d7

Browse files
committed
add tests
1 parent 3f8792c commit a9848d7

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

integration/single-fetch-test.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,86 @@ test.describe("single-fetch", () => {
34293429
await page.waitForSelector("#other");
34303430
expect(msgs).toEqual([]);
34313431
});
3432+
3433+
test("Aborted loaders don't cause corresponding result not found errors", async ({ page }) => {
3434+
let fixture = await createFixture({
3435+
files: {
3436+
...files,
3437+
"app/routes/_index.tsx": js`
3438+
import { useEffect } from "react";
3439+
import { Form, redirect, useFetcher, NavLink } from "react-router";
3440+
3441+
export default function Index() {
3442+
return (
3443+
<>
3444+
<NavLink id="linkA" to="/a" end>
3445+
Link
3446+
</NavLink>
3447+
</>
3448+
);
3449+
}
3450+
`,
3451+
"app/routes/a.tsx": js`
3452+
import { useEffect } from "react";
3453+
import { useFetcher, NavLink, Outlet } from "react-router";
3454+
3455+
export default function Comp() {
3456+
const loaderFetcher = useFetcher();
3457+
const actionFetcher = useFetcher();
3458+
3459+
useEffect(() => {
3460+
if (loaderFetcher.state === 'idle' && !loaderFetcher.data) {
3461+
loaderFetcher.load('/loader');
3462+
}
3463+
}, [loaderFetcher]);
3464+
3465+
return (
3466+
<>
3467+
<p id="a">A</p>
3468+
<button id="action" onClick={() => actionFetcher.submit(null, { method: "post", action: "/action" })}>
3469+
Action
3470+
</button>
3471+
<NavLink id="linkB" to="/a/b" end>
3472+
Link
3473+
</NavLink>
3474+
<Outlet/>
3475+
</>
3476+
);
3477+
}
3478+
`,
3479+
"app/routes/a.b.tsx": js`
3480+
export default function Comp() {
3481+
return <p id="b">B</p>;
3482+
}
3483+
`,
3484+
"app/routes/loader.tsx": js`
3485+
export async function loader() {
3486+
await new Promise((r) => setTimeout(r, 500));
3487+
return 'nope';
3488+
}
3489+
`,
3490+
"app/routes/action.tsx": js`
3491+
export async function action() {
3492+
await new Promise((r) => setTimeout(r, 500));
3493+
return 'nope';
3494+
}
3495+
`,
3496+
},
3497+
});
3498+
let appFixture = await createAppFixture(fixture);
3499+
let app = new PlaywrightFixture(appFixture, page);
3500+
3501+
// Capture console logs and uncaught errors
3502+
let msgs: string[] = [];
3503+
page.on("console", (msg) => msgs.push(msg.text()));
3504+
page.on("pageerror", (error) => msgs.push(error.message));
3505+
3506+
await app.goto("/a", true);
3507+
await page.locator("#action").click();
3508+
await page.locator("#linkB").click();
3509+
await page.waitForSelector("#b");
3510+
expect(msgs).toEqual([]);
3511+
});
34323512
});
34333513

34343514
test.describe("prefetching", () => {

0 commit comments

Comments
 (0)