Skip to content

Commit

Permalink
sleep -> await
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- committed Jun 10, 2024
1 parent 412a12e commit 1682389
Showing 1 changed file with 25 additions and 37 deletions.
62 changes: 25 additions & 37 deletions packages/react-router-dom/__tests__/use-blocker-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,9 @@ describe("navigation blocking with useBlocker", () => {
it("navigates", async () => {
await act(async () => {
click(node.querySelector("a[href='/about']"));
await sleep(LOADER_LATENCY_MS);
});
let h1 = node.querySelector("h1");
expect(h1?.textContent).toBe("About");
await waitFor(() => expect(h1?.textContent).toBe("About"));
});

it("gets an 'unblocked' blocker after navigation starts", async () => {
Expand All @@ -301,14 +300,15 @@ describe("navigation blocking with useBlocker", () => {
it("gets an 'unblocked' blocker after navigation completes", async () => {
await act(async () => {
click(node.querySelector("a[href='/about']"));
await sleep(LOADER_LATENCY_MS);
});
expect(blocker).toEqual({
state: "unblocked",
proceed: undefined,
reset: undefined,
location: undefined,
});
await waitFor(() =>
expect(blocker).toEqual({
state: "unblocked",
proceed: undefined,
reset: undefined,
location: undefined,
})
);
});
});

Expand Down Expand Up @@ -486,7 +486,6 @@ describe("navigation blocking with useBlocker", () => {
});
await act(async () => {
click(node.querySelector("[data-action='proceed']"));
await sleep(LOADER_LATENCY_MS);
});
let h1 = node.querySelector("h1");
await waitFor(() => expect(h1?.textContent).toBe("About"));
Expand All @@ -513,8 +512,6 @@ describe("navigation blocking with useBlocker", () => {
});
await act(async () => {
click(node.querySelector("[data-action='reset']"));
// wait for '/about' loader so we catch failure if navigation proceeds
await sleep(LOADER_LATENCY_MS);
});
let h1 = node.querySelector("h1");
await waitFor(() => expect(h1?.textContent).toBe("Home"));
Expand Down Expand Up @@ -576,7 +573,6 @@ describe("navigation blocking with useBlocker", () => {
it("navigates", async () => {
await act(async () => {
click(node.querySelector("a[href='/about']"));
await sleep(LOADER_LATENCY_MS);
});
let h1 = node.querySelector("h1");
await waitFor(() => expect(h1?.textContent).toBe("About"));
Expand Down Expand Up @@ -661,7 +657,6 @@ describe("navigation blocking with useBlocker", () => {
it("does not navigate", async () => {
await act(async () => {
click(node.querySelector("a[href='/about']"));
await sleep(LOADER_LATENCY_MS);
});
let h1 = node.querySelector("h1");
await waitFor(() => expect(h1?.textContent).not.toBe("About"));
Expand Down Expand Up @@ -774,14 +769,15 @@ describe("navigation blocking with useBlocker", () => {
});
await act(async () => {
click(node.querySelector("[data-action='proceed']"));
await sleep(LOADER_LATENCY_MS);
});
expect(blocker).toEqual({
state: "unblocked",
proceed: undefined,
reset: undefined,
location: undefined,
});
await waitFor(() =>
expect(blocker).toEqual({
state: "unblocked",
proceed: undefined,
reset: undefined,
location: undefined,
})
);
});

it("navigates after proceeding navigation completes", async () => {
Expand All @@ -790,7 +786,6 @@ describe("navigation blocking with useBlocker", () => {
});
await act(async () => {
click(node.querySelector("[data-action='proceed']"));
await sleep(LOADER_LATENCY_MS);
});
let h1 = node.querySelector("h1");
await waitFor(() => expect(h1?.textContent).toBe("About"));
Expand All @@ -817,8 +812,6 @@ describe("navigation blocking with useBlocker", () => {
});
await act(async () => {
click(node.querySelector("[data-action='reset']"));
// wait for '/about' loader so we catch failure if navigation proceeds
await sleep(LOADER_LATENCY_MS);
});
let h1 = node.querySelector("h1");
await waitFor(() => expect(h1?.textContent).toBe("Home"));
Expand Down Expand Up @@ -888,7 +881,6 @@ describe("navigation blocking with useBlocker", () => {
it("navigates", async () => {
await act(async () => {
click(node.querySelector("[data-action='back']"));
await sleep(LOADER_LATENCY_MS);
});
let h1 = node.querySelector("h1");
await waitFor(() => expect(h1?.textContent).toBe("About"));
Expand All @@ -909,7 +901,6 @@ describe("navigation blocking with useBlocker", () => {
it("gets an 'unblocked' blocker after navigation completes", async () => {
await act(async () => {
click(node.querySelector("[data-action='back']"));
await sleep(LOADER_LATENCY_MS);
});
expect(blocker).toEqual({
state: "unblocked",
Expand Down Expand Up @@ -981,7 +972,6 @@ describe("navigation blocking with useBlocker", () => {
it("does not navigate", async () => {
await act(async () => {
click(node.querySelector("[data-action='back']"));
await sleep(LOADER_LATENCY_MS);
});
let h1 = node.querySelector("h1");
await waitFor(() => expect(h1?.textContent).not.toBe("About"));
Expand All @@ -1002,7 +992,6 @@ describe("navigation blocking with useBlocker", () => {
it("gets a 'blocked' blocker after navigation promise resolves", async () => {
await act(async () => {
click(node.querySelector("[data-action='back']"));
await sleep(LOADER_LATENCY_MS);
});
expect(blocker).toEqual({
state: "blocked",
Expand Down Expand Up @@ -1102,14 +1091,15 @@ describe("navigation blocking with useBlocker", () => {
});
await act(async () => {
click(node.querySelector("[data-action='proceed']"));
await sleep(LOADER_LATENCY_MS);
});
expect(blocker).toEqual({
state: "unblocked",
proceed: undefined,
reset: undefined,
location: undefined,
});
await waitFor(() =>
expect(blocker).toEqual({
state: "unblocked",
proceed: undefined,
reset: undefined,
location: undefined,
})
);
});

it("navigates after proceeding navigation completes", async () => {
Expand All @@ -1118,7 +1108,6 @@ describe("navigation blocking with useBlocker", () => {
});
await act(async () => {
click(node.querySelector("[data-action='proceed']"));
await sleep(LOADER_LATENCY_MS);
});
let h1 = node.querySelector("h1");
await waitFor(() => expect(h1?.textContent).toBe("About"));
Expand Down Expand Up @@ -1146,7 +1135,6 @@ describe("navigation blocking with useBlocker", () => {
await act(async () => {
click(node.querySelector("[data-action='reset']"));
// wait for '/about' loader so we catch failure if navigation proceeds
await sleep(LOADER_LATENCY_MS);
});
let h1 = node.querySelector("h1");
await waitFor(() => expect(h1?.textContent).toBe("Contact"));
Expand Down

0 comments on commit 1682389

Please sign in to comment.