From 82ede5a10735f3d5c6d2e76699babc085f5910d4 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Sun, 29 Mar 2026 01:03:11 -0700 Subject: [PATCH] =?UTF-8?q?fix(web):=20add=20Next.js=20module=20mocks=20fo?= =?UTF-8?q?r=20Vitest=20=E2=80=94=20all=2014=20tests=20pass=20(was=2010/14?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/test/__mocks__/next-link.tsx | 5 +++++ web/src/test/__mocks__/next-navigation.ts | 13 +++++++++++++ web/vitest.config.ts | 2 ++ 3 files changed, 20 insertions(+) create mode 100644 web/src/test/__mocks__/next-link.tsx create mode 100644 web/src/test/__mocks__/next-navigation.ts diff --git a/web/src/test/__mocks__/next-link.tsx b/web/src/test/__mocks__/next-link.tsx new file mode 100644 index 0000000..13b43cf --- /dev/null +++ b/web/src/test/__mocks__/next-link.tsx @@ -0,0 +1,5 @@ +import * as React from 'react'; + +export default function Link({ href, children, ...props }: React.ComponentProps<'a'> & { href: string }) { + return {children}; +} diff --git a/web/src/test/__mocks__/next-navigation.ts b/web/src/test/__mocks__/next-navigation.ts new file mode 100644 index 0000000..42c33fa --- /dev/null +++ b/web/src/test/__mocks__/next-navigation.ts @@ -0,0 +1,13 @@ +export const usePathname = () => '/dashboard'; +export const useRouter = () => ({ + push: () => {}, + replace: () => {}, + back: () => {}, + forward: () => {}, + refresh: () => {}, + prefetch: () => {}, +}); +export const useSearchParams = () => new URLSearchParams(); +export const useParams = () => ({}); +export const redirect = () => {}; +export const notFound = () => {}; diff --git a/web/vitest.config.ts b/web/vitest.config.ts index 500890d..7ce5e38 100644 --- a/web/vitest.config.ts +++ b/web/vitest.config.ts @@ -11,6 +11,8 @@ export default defineConfig({ resolve: { alias: { "@": path.resolve(__dirname, "./src"), + "next/navigation": path.resolve(__dirname, "./src/test/__mocks__/next-navigation.ts"), + "next/link": path.resolve(__dirname, "./src/test/__mocks__/next-link.tsx"), }, }, });