From ec641b8150b7a109707719f4cb2c329628a3cf6e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 23 Nov 2024 15:58:05 +0000 Subject: [PATCH 1/8] chore(deps): bump react-router-dom from 6.28.0 to 7.0.1 in /client Bumps [react-router-dom](https://github.com/remix-run/react-router/tree/HEAD/packages/react-router-dom) from 6.28.0 to 7.0.1. - [Release notes](https://github.com/remix-run/react-router/releases) - [Changelog](https://github.com/remix-run/react-router/blob/main/packages/react-router-dom/CHANGELOG.md) - [Commits](https://github.com/remix-run/react-router/commits/react-router-dom@7.0.1/packages/react-router-dom) --- updated-dependencies: - dependency-name: react-router-dom dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- client/package-lock.json | 72 +++++++++++++++++++++++++--------------- client/package.json | 2 +- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index 0c292fd..bc3b7e1 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -14,7 +14,7 @@ "lucide-react": "^0.440.0", "react": "^18.3.1", "react-dom": "^18.3.1", - "react-router-dom": "^6.26.2", + "react-router-dom": "^7.0.1", "react-tooltip": "^5.28.0", "sonner": "^1.5.0", "zustand": "^5.0.1" @@ -840,15 +840,6 @@ "node": ">=14" } }, - "node_modules/@remix-run/router": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.21.0.tgz", - "integrity": "sha512-xfSkCAchbdG5PnbrKqFWwia4Bi61nH+wm8wLEqfHDyp7Y3dZzgqS2itV8i4gAq9pC2HsTpwyBC6Ds8VHZ96JlA==", - "license": "MIT", - "engines": { - "node": ">=14.0.0" - } - }, "node_modules/@rollup/rollup-android-arm-eabi": { "version": "4.27.2", "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.27.2.tgz", @@ -1452,6 +1443,11 @@ "license": "MIT", "peer": true }, + "node_modules/@types/cookie": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.6.0.tgz", + "integrity": "sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==" + }, "node_modules/@types/estree": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", @@ -2304,6 +2300,14 @@ "dev": true, "license": "MIT" }, + "node_modules/cookie": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-1.0.2.tgz", + "integrity": "sha512-9Kr/j4O16ISv8zBBhJoi4bXOYNTkFLOqSL3UDB0njXxCXNezjeyVrJyGOWtgfs/q2km1gwBcfH8q1yEGoMYunA==", + "engines": { + "node": ">=18" + } + }, "node_modules/cookies": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/cookies/-/cookies-0.9.1.tgz", @@ -4142,35 +4146,41 @@ "peer": true }, "node_modules/react-router": { - "version": "6.28.0", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.28.0.tgz", - "integrity": "sha512-HrYdIFqdrnhDw0PqG/AKjAqEqM7AvxCz0DQ4h2W8k6nqmc5uRBYDag0SBxx9iYz5G8gnuNVLzUe13wl9eAsXXg==", - "license": "MIT", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-7.0.1.tgz", + "integrity": "sha512-WVAhv9oWCNsja5AkK6KLpXJDSJCQizOIyOd4vvB/+eHGbYx5vkhcmcmwWjQ9yqkRClogi+xjEg9fNEOd5EX/tw==", "dependencies": { - "@remix-run/router": "1.21.0" + "@types/cookie": "^0.6.0", + "cookie": "^1.0.1", + "set-cookie-parser": "^2.6.0", + "turbo-stream": "2.4.0" }, "engines": { - "node": ">=14.0.0" + "node": ">=20.0.0" }, "peerDependencies": { - "react": ">=16.8" + "react": ">=18", + "react-dom": ">=18" + }, + "peerDependenciesMeta": { + "react-dom": { + "optional": true + } } }, "node_modules/react-router-dom": { - "version": "6.28.0", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.28.0.tgz", - "integrity": "sha512-kQ7Unsl5YdyOltsPGl31zOjLrDv+m2VcIEcIHqYYD3Lp0UppLjrzcfJqDJwXxFw3TH/yvapbnUvPlAj7Kx5nbg==", - "license": "MIT", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-7.0.1.tgz", + "integrity": "sha512-duBzwAAiIabhFPZfDjcYpJ+f08TMbPMETgq254GWne2NW1ZwRHhZLj7tpSp8KGb7JvZzlLcjGUnqLxpZQVEPng==", "dependencies": { - "@remix-run/router": "1.21.0", - "react-router": "6.28.0" + "react-router": "7.0.1" }, "engines": { - "node": ">=14.0.0" + "node": ">=20.0.0" }, "peerDependencies": { - "react": ">=16.8", - "react-dom": ">=16.8" + "react": ">=18", + "react-dom": ">=18" } }, "node_modules/react-tooltip": { @@ -4381,6 +4391,11 @@ "node": ">=10" } }, + "node_modules/set-cookie-parser": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.1.tgz", + "integrity": "sha512-IOc8uWeOZgnb3ptbCURJWNjWUPcO3ZnTTdzsurqERrP6nPyv+paC55vJM0LpOlT2ne+Ix+9+CRG1MNLlyZ4GjQ==" + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -4830,6 +4845,11 @@ "node": ">=0.6.x" } }, + "node_modules/turbo-stream": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/turbo-stream/-/turbo-stream-2.4.0.tgz", + "integrity": "sha512-FHncC10WpBd2eOmGwpmQsWLDoK4cqsA/UT/GqNoaKOQnT8uzhtCbg3EoUDMvqpOSAI0S26mr0rkjzbOO6S3v1g==" + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", diff --git a/client/package.json b/client/package.json index feef4d4..1e97fd8 100644 --- a/client/package.json +++ b/client/package.json @@ -21,7 +21,7 @@ "lucide-react": "^0.440.0", "react": "^18.3.1", "react-dom": "^18.3.1", - "react-router-dom": "^6.26.2", + "react-router-dom": "^7.0.1", "react-tooltip": "^5.28.0", "sonner": "^1.5.0", "zustand": "^5.0.1" From 92b700d09ca0d32aa6755d5cbea4f7798736f6a5 Mon Sep 17 00:00:00 2001 From: Fingertips Date: Sun, 24 Nov 2024 00:34:33 +0800 Subject: [PATCH 2/8] fix: Update auth guard test --- client/src/guards/auth-guard.test.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/src/guards/auth-guard.test.tsx b/client/src/guards/auth-guard.test.tsx index a78ed01..88584ac 100644 --- a/client/src/guards/auth-guard.test.tsx +++ b/client/src/guards/auth-guard.test.tsx @@ -51,12 +51,19 @@ describe("Auth Guard", () => { }); it("renders the outlet when not authorized", () => { + // Change the mock return value to simulate an unauthorized user (useAuthStore as unknown as Mock).mockReturnValueOnce({ authorized: false, }); + // Update the router state to reflect the new authorization state + router = createMemoryRouter(routes, { + initialEntries: [AppRoutes.SignIn], + }); + render(); - expect(router); + // Assert that the Sign In page is rendered + expect(router.state.location.pathname).toBe(AppRoutes.SignIn); }); }); From afba7d5f67b47e14f74be8d503b7d0856050c972 Mon Sep 17 00:00:00 2001 From: Fingertips Date: Sun, 24 Nov 2024 00:42:17 +0800 Subject: [PATCH 3/8] fix: Remove auth guard test before all --- client/src/guards/auth-guard.test.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/client/src/guards/auth-guard.test.tsx b/client/src/guards/auth-guard.test.tsx index 88584ac..d9f0e44 100644 --- a/client/src/guards/auth-guard.test.tsx +++ b/client/src/guards/auth-guard.test.tsx @@ -3,7 +3,7 @@ import { RouteObject, RouterProvider, } from "react-router-dom"; -import { describe, it, expect, vi, Mock, beforeAll } from "vitest"; +import { describe, it, expect, vi, Mock } from "vitest"; import { render } from "@testing-library/react"; import { useAuthStore } from "@/lib/stores/auth-store"; @@ -32,21 +32,19 @@ const routes: RouteObject[] = [ ]; describe("Auth Guard", () => { - let router: ReturnType; - - beforeAll(() => { + it("redirects to the root page when authorized", () => { (useAuthStore as unknown as Mock).mockReturnValueOnce({ authorized: true, }); - router = createMemoryRouter(routes, { + // Update the router state to reflect the new authorization state + const router = createMemoryRouter(routes, { initialEntries: [AppRoutes.SignIn], }); render(); - }); - it("redirects to the root page when authorized", () => { + // Assert that the Root page is rendered expect(router.state.location.pathname).toBe(AppRoutes.Root); }); @@ -56,8 +54,7 @@ describe("Auth Guard", () => { authorized: false, }); - // Update the router state to reflect the new authorization state - router = createMemoryRouter(routes, { + const router = createMemoryRouter(routes, { initialEntries: [AppRoutes.SignIn], }); From 293261c92c201886e3cda8523f9f833b20903d34 Mon Sep 17 00:00:00 2001 From: Fingertips Date: Sun, 24 Nov 2024 03:19:18 +0800 Subject: [PATCH 4/8] fix: Add await in auth guard test --- client/src/guards/auth-guard.test.tsx | 35 +++++++++++++++------------ 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/client/src/guards/auth-guard.test.tsx b/client/src/guards/auth-guard.test.tsx index d9f0e44..93de26f 100644 --- a/client/src/guards/auth-guard.test.tsx +++ b/client/src/guards/auth-guard.test.tsx @@ -3,8 +3,9 @@ import { RouteObject, RouterProvider, } from "react-router-dom"; -import { describe, it, expect, vi, Mock } from "vitest"; -import { render } from "@testing-library/react"; +import { describe, it, expect, vi, Mock, beforeAll } from "vitest"; +import { render, waitFor } from "@testing-library/react"; +import { Router } from "@remix-run/router"; import { useAuthStore } from "@/lib/stores/auth-store"; import { AppRoutes } from "@/constants/routes"; @@ -32,35 +33,39 @@ const routes: RouteObject[] = [ ]; describe("Auth Guard", () => { - it("redirects to the root page when authorized", () => { + let router: Router; + + beforeAll(() => { (useAuthStore as unknown as Mock).mockReturnValueOnce({ authorized: true, }); - // Update the router state to reflect the new authorization state - const router = createMemoryRouter(routes, { + router = createMemoryRouter(routes, { initialEntries: [AppRoutes.SignIn], }); + }); + it("redirects to the root page when authorized", async () => { render(); - // Assert that the Root page is rendered - expect(router.state.location.pathname).toBe(AppRoutes.Root); + await waitFor(() => { + expect(router.state.location.pathname).toBe(AppRoutes.Root); + }); }); - it("renders the outlet when not authorized", () => { - // Change the mock return value to simulate an unauthorized user - (useAuthStore as unknown as Mock).mockReturnValueOnce({ - authorized: false, + it("renders the outlet when not authorized", async () => { + router = createMemoryRouter(routes, { + initialEntries: [AppRoutes.SignIn], }); - const router = createMemoryRouter(routes, { - initialEntries: [AppRoutes.SignIn], + (useAuthStore as unknown as Mock).mockReturnValueOnce({ + authorized: false, }); render(); - // Assert that the Sign In page is rendered - expect(router.state.location.pathname).toBe(AppRoutes.SignIn); + await waitFor(() => { + expect(router.state.location.pathname).toBe(AppRoutes.SignIn); + }); }); }); From edf5cb343548d8bbe2175c7922e98e8f8bbcfc75 Mon Sep 17 00:00:00 2001 From: Fingertips Date: Sun, 24 Nov 2024 03:22:34 +0800 Subject: [PATCH 5/8] fix: Move useAuthStore declaration on top of the test cases --- client/src/guards/auth-guard.test.tsx | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/client/src/guards/auth-guard.test.tsx b/client/src/guards/auth-guard.test.tsx index 93de26f..ed4621d 100644 --- a/client/src/guards/auth-guard.test.tsx +++ b/client/src/guards/auth-guard.test.tsx @@ -3,9 +3,8 @@ import { RouteObject, RouterProvider, } from "react-router-dom"; -import { describe, it, expect, vi, Mock, beforeAll } from "vitest"; +import { describe, it, expect, vi, Mock } from "vitest"; import { render, waitFor } from "@testing-library/react"; -import { Router } from "@remix-run/router"; import { useAuthStore } from "@/lib/stores/auth-store"; import { AppRoutes } from "@/constants/routes"; @@ -33,19 +32,14 @@ const routes: RouteObject[] = [ ]; describe("Auth Guard", () => { - let router: Router; - - beforeAll(() => { + it("redirects to the root page when authorized", async () => { (useAuthStore as unknown as Mock).mockReturnValueOnce({ authorized: true, }); - router = createMemoryRouter(routes, { + const router = createMemoryRouter(routes, { initialEntries: [AppRoutes.SignIn], }); - }); - - it("redirects to the root page when authorized", async () => { render(); await waitFor(() => { @@ -54,14 +48,14 @@ describe("Auth Guard", () => { }); it("renders the outlet when not authorized", async () => { - router = createMemoryRouter(routes, { - initialEntries: [AppRoutes.SignIn], - }); - (useAuthStore as unknown as Mock).mockReturnValueOnce({ authorized: false, }); + const router = createMemoryRouter(routes, { + initialEntries: [AppRoutes.SignIn], + }); + render(); await waitFor(() => { From 8f0796a1ba68a4326d5e84e3c6961daee3a71bee Mon Sep 17 00:00:00 2001 From: Fingertips Date: Sun, 24 Nov 2024 03:57:26 +0800 Subject: [PATCH 6/8] fix: Change the import declaration for guard stores --- client/src/guards/auth-guard.test.tsx | 3 ++- client/src/guards/private-guard.test.tsx | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/client/src/guards/auth-guard.test.tsx b/client/src/guards/auth-guard.test.tsx index ed4621d..5a8df85 100644 --- a/client/src/guards/auth-guard.test.tsx +++ b/client/src/guards/auth-guard.test.tsx @@ -11,7 +11,7 @@ import { AppRoutes } from "@/constants/routes"; import AuthGuard from "./auth-guard"; -vi.mock("@/lib/stores/auth-store", () => ({ +vi.mock("../lib/stores/auth-store.ts", () => ({ useAuthStore: vi.fn(), })); @@ -40,6 +40,7 @@ describe("Auth Guard", () => { const router = createMemoryRouter(routes, { initialEntries: [AppRoutes.SignIn], }); + render(); await waitFor(() => { diff --git a/client/src/guards/private-guard.test.tsx b/client/src/guards/private-guard.test.tsx index c128d59..db619bb 100644 --- a/client/src/guards/private-guard.test.tsx +++ b/client/src/guards/private-guard.test.tsx @@ -14,14 +14,14 @@ import { AppRoutes } from "@/constants/routes"; import PrivateGuard from "./private-guard"; -vi.mock("@/lib/stores/auth-store", () => ({ +vi.mock("../lib/stores/auth-store.ts", () => ({ useAuthStore: vi.fn().mockReturnValueOnce({ authorized: false, setAuthorized: vi.fn(), }), })); -vi.mock("@/lib/stores/user-store", () => ({ +vi.mock("../lib/stores/user-store.ts", () => ({ useUserStore: vi.fn().mockReturnValueOnce({ setUser: vi.fn(), }), From 19013f732c83d29394897a201d8b54344f87907a Mon Sep 17 00:00:00 2001 From: Fingertips Date: Sun, 24 Nov 2024 04:08:12 +0800 Subject: [PATCH 7/8] fix: Use MemoryRouter component in auth guard test --- .github/workflows/client-test.yaml | 3 - client/src/guards/auth-guard.test.tsx | 70 ++++++++++++------------ client/src/guards/private-guard.test.tsx | 4 +- 3 files changed, 36 insertions(+), 41 deletions(-) diff --git a/.github/workflows/client-test.yaml b/.github/workflows/client-test.yaml index fc62423..750deb7 100644 --- a/.github/workflows/client-test.yaml +++ b/.github/workflows/client-test.yaml @@ -1,9 +1,6 @@ name: Client Test Workflow on: - push: - branches: - - main pull_request: branches: - main diff --git a/client/src/guards/auth-guard.test.tsx b/client/src/guards/auth-guard.test.tsx index 5a8df85..4596364 100644 --- a/client/src/guards/auth-guard.test.tsx +++ b/client/src/guards/auth-guard.test.tsx @@ -1,35 +1,21 @@ -import { - createMemoryRouter, - RouteObject, - RouterProvider, -} from "react-router-dom"; +import { MemoryRouter, Route, Routes, useLocation } from "react-router-dom"; +import { render, waitFor, screen } from "@testing-library/react"; import { describe, it, expect, vi, Mock } from "vitest"; -import { render, waitFor } from "@testing-library/react"; import { useAuthStore } from "@/lib/stores/auth-store"; import { AppRoutes } from "@/constants/routes"; - import AuthGuard from "./auth-guard"; -vi.mock("../lib/stores/auth-store.ts", () => ({ +// Mock the store +vi.mock("@/lib/stores/auth-store", () => ({ useAuthStore: vi.fn(), })); -const routes: RouteObject[] = [ - { - path: AppRoutes.Root, - element:
Root
, - }, - { - element: , - children: [ - { - path: AppRoutes.SignIn, - element:
Sign In
, - }, - ], - }, -]; +// Helper to track the current route location +function LocationDisplay() { + const location = useLocation(); + return
{location.pathname}
; +} describe("Auth Guard", () => { it("redirects to the root page when authorized", async () => { @@ -37,30 +23,42 @@ describe("Auth Guard", () => { authorized: true, }); - const router = createMemoryRouter(routes, { - initialEntries: [AppRoutes.SignIn], - }); - - render(); + render( + + + Root} /> + }> + Sign In} /> + + + {/* Track current location */} + + ); await waitFor(() => { - expect(router.state.location.pathname).toBe(AppRoutes.Root); + expect(screen.getByTestId("location").textContent).toBe(AppRoutes.Root); }); }); - it("renders the outlet when not authorized", async () => { + it("stays on /sign-in when not authorized", async () => { (useAuthStore as unknown as Mock).mockReturnValueOnce({ authorized: false, }); - const router = createMemoryRouter(routes, { - initialEntries: [AppRoutes.SignIn], - }); - - render(); + render( + + + Root} /> + }> + Sign In} /> + + + {/* Track current location */} + + ); await waitFor(() => { - expect(router.state.location.pathname).toBe(AppRoutes.SignIn); + expect(screen.getByTestId("location").textContent).toBe(AppRoutes.SignIn); }); }); }); diff --git a/client/src/guards/private-guard.test.tsx b/client/src/guards/private-guard.test.tsx index db619bb..c128d59 100644 --- a/client/src/guards/private-guard.test.tsx +++ b/client/src/guards/private-guard.test.tsx @@ -14,14 +14,14 @@ import { AppRoutes } from "@/constants/routes"; import PrivateGuard from "./private-guard"; -vi.mock("../lib/stores/auth-store.ts", () => ({ +vi.mock("@/lib/stores/auth-store", () => ({ useAuthStore: vi.fn().mockReturnValueOnce({ authorized: false, setAuthorized: vi.fn(), }), })); -vi.mock("../lib/stores/user-store.ts", () => ({ +vi.mock("@/lib/stores/user-store", () => ({ useUserStore: vi.fn().mockReturnValueOnce({ setUser: vi.fn(), }), From fe842ca86a1d8971996ee34ee72e94b84420372b Mon Sep 17 00:00:00 2001 From: Fingertips Date: Sun, 24 Nov 2024 04:18:21 +0800 Subject: [PATCH 8/8] fix: Use MemoryRouter component in private guard test --- client/src/guards/private-guard.test.tsx | 114 +++++++++++++---------- 1 file changed, 65 insertions(+), 49 deletions(-) diff --git a/client/src/guards/private-guard.test.tsx b/client/src/guards/private-guard.test.tsx index c128d59..ce58230 100644 --- a/client/src/guards/private-guard.test.tsx +++ b/client/src/guards/private-guard.test.tsx @@ -1,11 +1,7 @@ -import { - createMemoryRouter, - RouteObject, - RouterProvider, -} from "react-router-dom"; +import { MemoryRouter, Route, Routes, useLocation } from "react-router-dom"; +import { render, waitFor, screen } from "@testing-library/react"; import { describe, it, expect, vi, Mock } from "vitest"; import { useQuery } from "@tanstack/react-query"; -import { render } from "@testing-library/react"; import "@testing-library/jest-dom"; import { useAuthStore } from "@/lib/stores/auth-store"; @@ -45,38 +41,32 @@ vi.mock("@tanstack/react-query", () => ({ }), })); -const routes: RouteObject[] = [ - { - path: AppRoutes.SignIn, - element:
Sign In
, - }, - { - element: , - children: [ - { - path: AppRoutes.Root, - element:
Root
, - }, - ], - }, -]; +// Helper to track the current route location +function LocationDisplay() { + const location = useLocation(); + return
{location.pathname}
; +} describe("Private Guard", () => { - it("redirects to sign-in page when not authorized", () => { - const router = createMemoryRouter(routes, { - initialEntries: [AppRoutes.Root], + it("redirects to sign-in page when not authorized", async () => { + render( + + + Sign In} /> + }> + Root} /> + + + {/* Track current location */} + + ); + + await waitFor(() => { + expect(screen.getByTestId("location").textContent).toBe(AppRoutes.SignIn); }); - - render(); - - expect(router.state.location.pathname).toEqual(AppRoutes.SignIn); }); - it("redirects to sign in page when an error occurs", () => { - const router = createMemoryRouter(routes, { - initialEntries: [AppRoutes.Root], - }); - + it("redirects to sign in page when an error occurs", async () => { (useUserStore as unknown as Mock).mockRejectedValueOnce({ setUser: vi.fn(), }); @@ -95,16 +85,24 @@ describe("Private Guard", () => { }, }); - render(); - - expect(router.state.location.pathname).toEqual(AppRoutes.SignIn); - }); - - it("allows access to root page when authorized", () => { - const router = createMemoryRouter(routes, { - initialEntries: [AppRoutes.Root], + render( + + + Sign In} /> + }> + Root} /> + + + {/* Track current location */} + + ); + + await waitFor(() => { + expect(screen.getByTestId("location").textContent).toBe(AppRoutes.SignIn); }); + }); + it("allows access to root page when authorized", async () => { (useUserStore as unknown as Mock).mockReturnValueOnce({ setUser: vi.fn(), }); @@ -123,16 +121,24 @@ describe("Private Guard", () => { }, }); - render(); - - expect(router.state.location.pathname).toEqual(AppRoutes.Root); + render( + + + Sign In} /> + }> + Root} /> + + + {/* Track current location */} + + ); + + await waitFor(() => { + expect(screen.getByTestId("location").textContent).toBe(AppRoutes.Root); + }); }); it("renders loading component when query is loading", () => { - const router = createMemoryRouter(routes, { - initialEntries: [AppRoutes.Root], - }); - (useUserStore as unknown as Mock).mockRejectedValueOnce({ useUser: vi.fn(), }); @@ -148,7 +154,17 @@ describe("Private Guard", () => { isSuccess: false, }); - const { container } = render(); + const { container } = render( + + + Sign In} /> + }> + Root} /> + + + {/* Track current location */} + + ); const loader = container.querySelector("svg");