|
1 | 1 | import type { ActiveSessionResource, LoadedClerk } from '@clerk/types'; |
2 | 2 | import { type Mocked, vi } from 'vitest'; |
3 | 3 |
|
| 4 | +import { QueryClient } from '../core/query-core'; |
4 | 5 | import type { RouteContextValue } from '../ui/router'; |
5 | 6 |
|
6 | 7 | type FunctionLike = (...args: any) => any; |
@@ -45,6 +46,18 @@ export const mockClerkMethods = (clerk: LoadedClerk): DeepVitestMocked<LoadedCle |
45 | 46 | // Cast clerk to any to allow mocking properties |
46 | 47 | const clerkAny = clerk as any; |
47 | 48 |
|
| 49 | + const defaultQueryClient = { |
| 50 | + __tag: 'clerk-rq-client' as const, |
| 51 | + client: new QueryClient({ |
| 52 | + defaultOptions: { |
| 53 | + queries: { |
| 54 | + retry: false, |
| 55 | + staleTime: 0, |
| 56 | + }, |
| 57 | + }, |
| 58 | + }), |
| 59 | + }; |
| 60 | + |
48 | 61 | mockMethodsOf(clerkAny); |
49 | 62 | if (clerkAny.client) { |
50 | 63 | mockMethodsOf(clerkAny.client.signIn); |
@@ -76,6 +89,13 @@ export const mockClerkMethods = (clerk: LoadedClerk): DeepVitestMocked<LoadedCle |
76 | 89 | if (clerkAny.billing) { |
77 | 90 | mockMethodsOf(clerkAny.billing); |
78 | 91 | } |
| 92 | + |
| 93 | + // Mock the __internal_queryClient getter property |
| 94 | + Object.defineProperty(clerkAny, '__internal_queryClient', { |
| 95 | + get: vi.fn(() => defaultQueryClient), |
| 96 | + configurable: true, |
| 97 | + }); |
| 98 | + |
79 | 99 | mockProp(clerkAny, 'navigate'); |
80 | 100 | mockProp(clerkAny, 'setActive'); |
81 | 101 | mockProp(clerkAny, 'redirectWithAuth'); |
|
0 commit comments