-
Notifications
You must be signed in to change notification settings - Fork 452
Expand file tree
/
Copy pathclerk-client.test.ts
More file actions
54 lines (42 loc) · 1.53 KB
/
clerk-client.test.ts
File metadata and controls
54 lines (42 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { beforeEach, describe, expect, it, vi } from 'vitest';
const mockLoad = vi.fn().mockResolvedValue(undefined);
const mockUi = { __brand: 'clerk-ui', ClerkUI: vi.fn() };
vi.mock('@clerk/clerk-js/no-rhc', () => {
const Clerk = vi.fn(function () {
return { load: mockLoad };
}) as ReturnType<typeof vi.fn> & { sdkMetadata: Record<string, string> };
Clerk.sdkMetadata = {};
return { Clerk };
});
vi.mock('@clerk/ui/no-rhc', () => ({
ui: mockUi,
}));
import { createClerkClient } from '../clerk-client';
describe('createClerkClient', () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe('non-background (popup)', () => {
it('returns a Clerk instance synchronously', () => {
const clerk = createClerkClient({ publishableKey: 'pk_test_123' });
expect(clerk).toBeDefined();
expect(clerk).not.toBeInstanceOf(Promise);
});
it('wraps load() to inject @clerk/ui', async () => {
const clerk = createClerkClient({ publishableKey: 'pk_test_123' });
const loadOpts = { afterSignOutUrl: '/signed-out' };
await clerk.load(loadOpts);
expect(mockLoad).toHaveBeenCalledOnce();
expect(mockLoad).toHaveBeenCalledWith({
...loadOpts,
ui: mockUi,
});
});
it('calls load() with ui even when no options are passed', async () => {
const clerk = createClerkClient({ publishableKey: 'pk_test_123' });
await clerk.load();
expect(mockLoad).toHaveBeenCalledOnce();
expect(mockLoad).toHaveBeenCalledWith({ ui: mockUi });
});
});
});