Skip to content

Commit f8bee5d

Browse files
committed
mock queryClient
1 parent f9b7f64 commit f8bee5d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/clerk-js/src/test/mock-helpers.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ActiveSessionResource, LoadedClerk } from '@clerk/types';
22
import { type Mocked, vi } from 'vitest';
33

4+
import { QueryClient } from '../core/query-core';
45
import type { RouteContextValue } from '../ui/router';
56

67
type FunctionLike = (...args: any) => any;
@@ -45,6 +46,18 @@ export const mockClerkMethods = (clerk: LoadedClerk): DeepVitestMocked<LoadedCle
4546
// Cast clerk to any to allow mocking properties
4647
const clerkAny = clerk as any;
4748

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+
4861
mockMethodsOf(clerkAny);
4962
if (clerkAny.client) {
5063
mockMethodsOf(clerkAny.client.signIn);
@@ -76,6 +89,13 @@ export const mockClerkMethods = (clerk: LoadedClerk): DeepVitestMocked<LoadedCle
7689
if (clerkAny.billing) {
7790
mockMethodsOf(clerkAny.billing);
7891
}
92+
93+
// Mock the __internal_queryClient getter property
94+
Object.defineProperty(clerkAny, '__internal_queryClient', {
95+
get: vi.fn(() => defaultQueryClient),
96+
configurable: true,
97+
});
98+
7999
mockProp(clerkAny, 'navigate');
80100
mockProp(clerkAny, 'setActive');
81101
mockProp(clerkAny, 'redirectWithAuth');

0 commit comments

Comments
 (0)