From 6899367008674551350e20f69e61ce21ac8bcdaf Mon Sep 17 00:00:00 2001 From: Himarghya Date: Wed, 7 Oct 2026 15:28:04 +0530 Subject: [PATCH] fix(tests): hoist vi.mock to top level in vitest setup --- vitest.setup.ts | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/vitest.setup.ts b/vitest.setup.ts index 1a40b1d35..d4184fbb6 100644 --- a/vitest.setup.ts +++ b/vitest.setup.ts @@ -1,4 +1,4 @@ -import { afterEach, vi, beforeAll } from 'vitest'; +import { afterEach, vi } from 'vitest'; // Track unhandled errors for better debugging const originalConsoleError = console.error; @@ -28,20 +28,17 @@ process.on('uncaughtException', error => { }); // Mock Astro content collections before any imports -beforeAll(() => { - // Mock astro:content module - vi.mock('astro:content', () => ({ - getEntry: vi.fn().mockResolvedValue({ - data: { - 'nav.home': 'Home', - 'nav.docs': 'Docs', - 'getting-started': 'Getting Started', - FAQ: 'FAQ' - } - }), - getCollection: vi.fn().mockResolvedValue([]) - })); -}); +vi.mock('astro:content', () => ({ + getEntry: vi.fn().mockResolvedValue({ + data: { + 'nav.home': 'Home', + 'nav.docs': 'Docs', + 'getting-started': 'Getting Started', + FAQ: 'FAQ' + } + }), + getCollection: vi.fn().mockResolvedValue([]) +})); // Global cleanup after each test afterEach(() => {