From 15781aa07efb5f8acdfff10dcf8590c4c5c713a5 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 10 Jun 2024 09:25:14 +0300 Subject: [PATCH] sleep -> await --- .../__tests__/use-blocker-test.tsx | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/react-router-dom/__tests__/use-blocker-test.tsx b/packages/react-router-dom/__tests__/use-blocker-test.tsx index 3bbeddc253..6dad917c57 100644 --- a/packages/react-router-dom/__tests__/use-blocker-test.tsx +++ b/packages/react-router-dom/__tests__/use-blocker-test.tsx @@ -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 () => { @@ -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, + }) + ); }); }); @@ -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 () => { @@ -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 () => { @@ -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")); @@ -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"));