Skip to content

Commit 684fb49

Browse files
committed
mock script loading and set up global Clerk objects for tests
1 parent c8b3b3d commit 684fb49

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/react/src/__tests__/isomorphicClerk.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,29 @@ import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
33

44
import { IsomorphicClerk } from '../isomorphicClerk';
55

6+
// Mock the script loading functions to prevent unhandled promise rejections in tests
7+
vi.mock('@clerk/shared/loadClerkJsScript', () => ({
8+
loadClerkJsScript: vi.fn().mockResolvedValue(null),
9+
loadClerkUiScript: vi.fn().mockResolvedValue(null),
10+
}));
11+
612
describe('isomorphicClerk', () => {
713
beforeAll(() => {
814
vi.useFakeTimers();
15+
16+
// Set up minimal global Clerk objects to prevent errors during initialization
17+
(global as any).Clerk = {
18+
load: vi.fn().mockResolvedValue(undefined),
19+
loaded: false,
20+
};
21+
(global as any).__unstable_ClerkUiCtor = vi.fn();
922
});
1023

1124
afterAll(() => {
1225
vi.useRealTimers();
26+
// Clean up globals
27+
delete (global as any).Clerk;
28+
delete (global as any).__unstable_ClerkUiCtor;
1329
});
1430

1531
it('instantiates a IsomorphicClerk instance', () => {

0 commit comments

Comments
 (0)