|
1 | 1 | import { createCookieHandler } from '@clerk/shared/cookie'; |
2 | 2 | import { addYears } from '@clerk/shared/date'; |
| 3 | +import { beforeEach, describe, expect, it, vi } from 'vitest'; |
3 | 4 |
|
4 | 5 | import { inCrossOriginIframe } from '../../../../utils'; |
5 | 6 | import { getCookieDomain } from '../../getCookieDomain'; |
6 | 7 | import { getSecureAttribute } from '../../getSecureAttribute'; |
7 | 8 | import { createClientUatCookie } from '../clientUat'; |
8 | 9 |
|
9 | | -jest.mock('@clerk/shared/cookie'); |
10 | | -jest.mock('@clerk/shared/date'); |
11 | | -jest.mock('../../../../utils'); |
12 | | -jest.mock('../../getCookieDomain'); |
13 | | -jest.mock('../../getSecureAttribute'); |
| 10 | +vi.mock('@clerk/shared/cookie'); |
| 11 | +vi.mock('@clerk/shared/date'); |
| 12 | +vi.mock('../../../../utils'); |
| 13 | +vi.mock('../../getCookieDomain'); |
| 14 | +vi.mock('../../getSecureAttribute'); |
14 | 15 |
|
15 | 16 | describe('createClientUatCookie', () => { |
16 | 17 | const mockCookieSuffix = 'test-suffix'; |
17 | 18 | const mockExpires = new Date('2024-12-31'); |
18 | 19 | const mockDomain = 'test.domain'; |
19 | | - const mockSet = jest.fn(); |
20 | | - const mockRemove = jest.fn(); |
21 | | - const mockGet = jest.fn(); |
| 20 | + const mockSet = vi.fn(); |
| 21 | + const mockRemove = vi.fn(); |
| 22 | + const mockGet = vi.fn(); |
22 | 23 |
|
23 | 24 | beforeEach(() => { |
24 | | - jest.clearAllMocks(); |
| 25 | + vi.clearAllMocks(); |
25 | 26 | mockGet.mockReset(); |
26 | | - (addYears as jest.Mock).mockReturnValue(mockExpires); |
27 | | - (inCrossOriginIframe as jest.Mock).mockReturnValue(false); |
28 | | - (getCookieDomain as jest.Mock).mockReturnValue(mockDomain); |
29 | | - (getSecureAttribute as jest.Mock).mockReturnValue(true); |
30 | | - (createCookieHandler as jest.Mock).mockImplementation(() => ({ |
| 27 | + (addYears as ReturnType<typeof vi.fn>).mockReturnValue(mockExpires); |
| 28 | + (inCrossOriginIframe as ReturnType<typeof vi.fn>).mockReturnValue(false); |
| 29 | + (getCookieDomain as ReturnType<typeof vi.fn>).mockReturnValue(mockDomain); |
| 30 | + (getSecureAttribute as ReturnType<typeof vi.fn>).mockReturnValue(true); |
| 31 | + (createCookieHandler as ReturnType<typeof vi.fn>).mockImplementation(() => ({ |
31 | 32 | set: mockSet, |
32 | 33 | remove: mockRemove, |
33 | 34 | get: mockGet, |
@@ -60,7 +61,7 @@ describe('createClientUatCookie', () => { |
60 | 61 | }); |
61 | 62 |
|
62 | 63 | it('should set cookies with None sameSite in cross-origin context', () => { |
63 | | - (inCrossOriginIframe as jest.Mock).mockReturnValue(true); |
| 64 | + (inCrossOriginIframe as ReturnType<typeof vi.fn>).mockReturnValue(true); |
64 | 65 | const cookieHandler = createClientUatCookie(mockCookieSuffix); |
65 | 66 | cookieHandler.set({ |
66 | 67 | id: 'test-client', |
|
0 commit comments