Skip to content

Commit

Permalink
Test for immediately proceeding blocker
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- committed Jul 23, 2024
1 parent cc8e434 commit 55fa06c
Showing 1 changed file with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { Router } from "../../lib/router";
import { createMemoryHistory, createRouter } from "../../lib/router";
import {
createBrowserHistory,
createMemoryHistory,
createRouter,
} from "../../lib/router";
import { waitFor } from "@testing-library/react";

const LOADER_LATENCY_MS = 100;
Expand Down Expand Up @@ -470,6 +474,41 @@ describe("navigation blocking", () => {
});
});

describe("proceeds from blocked state using browser history", () => {
let fn = () => true;

// we want to navigate so that `/about` is the previous entry in the
// stack here since it has a loader that won't resolve immediately
beforeEach(async () => {
const history = createBrowserHistory();

router = createRouter({
history,
routes,
});

router.initialize();

await router.navigate("/");
await router.navigate("/about");
await router.navigate("/contact");
});

it.only("navigates after proceeding navigation completes", async () => {
router.getBlocker("KEY", fn);

await router.navigate(-1); // This does not really wait for the navigation to happen
await waitFor(
() => expect(router.getBlocker("KEY", fn).state).toBe("blocked"),
{ interval: 1 }
); // This awaits the navigation
router.getBlocker("KEY", fn).proceed!();
await waitFor(() =>
expect(router.state.location.pathname).toBe("/about")
);
});
});

describe("resets from blocked state", () => {
let fn = () => true;
it("gets an 'unblocked' blocker after resetting navigation", async () => {
Expand Down

0 comments on commit 55fa06c

Please sign in to comment.