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 15781aa
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 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 @@ -774,14 +774,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 Down Expand Up @@ -1102,14 +1103,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 +1120,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 +1147,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 15781aa

Please sign in to comment.