From 6888f67f14621c1d8efb36f05dbb6f06163f445d Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sun, 31 May 2026 17:51:34 +0300 Subject: [PATCH] test(Font): make queryClient mock factory self-contained The vi.mock factory referenced the top-level QueryClient import. Once BaseQueryStore landed in the $shared/lib barrel, importing that barrel for createFilter eagerly pulled @tanstack/query-core into the init cycle, so the hoisted factory hit the import before initialization (Cannot access '__vi_import_2__' before initialization). Import QueryClient inside the factory to keep it independent of module order. --- .../fontCatalogStore/fontCatalogStore.svelte.spec.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/entities/Font/model/store/fontCatalogStore/fontCatalogStore.svelte.spec.ts b/src/entities/Font/model/store/fontCatalogStore/fontCatalogStore.svelte.spec.ts index 912d1d6..230512e 100644 --- a/src/entities/Font/model/store/fontCatalogStore/fontCatalogStore.svelte.spec.ts +++ b/src/entities/Font/model/store/fontCatalogStore/fontCatalogStore.svelte.spec.ts @@ -2,7 +2,6 @@ import { generateMixedCategoryFonts, generateMockFonts, } from '$entities/Font/testing'; -import { QueryClient } from '@tanstack/query-core'; import { flushSync } from 'svelte'; import { afterEach, @@ -20,6 +19,13 @@ import type { UnifiedFont } from '../../types'; import { FontCatalogStore } from './fontCatalogStore.svelte'; vi.mock('$shared/api/queryClient', async importOriginal => { + /** + * Import QueryClient inside the factory rather than referencing the top-level binding. + * A hoisted vi.mock factory that touches a module-level import can hit that import + * before it is initialized (ReferenceError) when the import sits in a circular/eager + * barrel chain — which it now does via $shared/lib → BaseQueryStore → query-core. + */ + const { QueryClient } = await import('@tanstack/query-core'); const actual = await importOriginal(); return { ...actual,