Skip to content

Commit 07e2724

Browse files
authored
chore(clerk-js): Additional tests converted to vitest (#6796)
1 parent aa92c1c commit 07e2724

File tree

22 files changed

+82
-46
lines changed

22 files changed

+82
-46
lines changed

.changeset/true-items-burn.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/clerk-js/src/core/auth/cookies/__tests__/clientUat.test.ts renamed to packages/clerk-js/src/core/auth/cookies/__tests__/clientUat.spec.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
import { createCookieHandler } from '@clerk/shared/cookie';
22
import { addYears } from '@clerk/shared/date';
3+
import { beforeEach, describe, expect, it, vi } from 'vitest';
34

45
import { inCrossOriginIframe } from '../../../../utils';
56
import { getCookieDomain } from '../../getCookieDomain';
67
import { getSecureAttribute } from '../../getSecureAttribute';
78
import { createClientUatCookie } from '../clientUat';
89

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');
1415

1516
describe('createClientUatCookie', () => {
1617
const mockCookieSuffix = 'test-suffix';
1718
const mockExpires = new Date('2024-12-31');
1819
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();
2223

2324
beforeEach(() => {
24-
jest.clearAllMocks();
25+
vi.clearAllMocks();
2526
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(() => ({
3132
set: mockSet,
3233
remove: mockRemove,
3334
get: mockGet,
@@ -60,7 +61,7 @@ describe('createClientUatCookie', () => {
6061
});
6162

6263
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);
6465
const cookieHandler = createClientUatCookie(mockCookieSuffix);
6566
cookieHandler.set({
6667
id: 'test-client',

packages/clerk-js/src/core/auth/cookies/__tests__/session.test.ts renamed to packages/clerk-js/src/core/auth/cookies/__tests__/session.spec.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
import { createCookieHandler } from '@clerk/shared/cookie';
22
import { addYears } from '@clerk/shared/date';
3+
import { beforeEach, describe, expect, it, vi } from 'vitest';
34

45
import { inCrossOriginIframe } from '../../../../utils';
56
import { getSecureAttribute } from '../../getSecureAttribute';
67
import { createSessionCookie } from '../session';
78

8-
jest.mock('@clerk/shared/cookie');
9-
jest.mock('@clerk/shared/date');
10-
jest.mock('../../../../utils');
11-
jest.mock('../../getSecureAttribute');
9+
vi.mock('@clerk/shared/cookie');
10+
vi.mock('@clerk/shared/date');
11+
vi.mock('../../../../utils');
12+
vi.mock('../../getSecureAttribute');
1213

1314
describe('createSessionCookie', () => {
1415
const mockCookieSuffix = 'test-suffix';
1516
const mockToken = 'test-token';
1617
const mockExpires = new Date('2024-12-31');
17-
const mockSet = jest.fn();
18-
const mockRemove = jest.fn();
19-
const mockGet = jest.fn();
18+
const mockSet = vi.fn();
19+
const mockRemove = vi.fn();
20+
const mockGet = vi.fn();
2021

2122
beforeEach(() => {
22-
jest.clearAllMocks();
23+
vi.clearAllMocks();
2324
mockGet.mockReset();
24-
(addYears as jest.Mock).mockReturnValue(mockExpires);
25-
(inCrossOriginIframe as jest.Mock).mockReturnValue(false);
26-
(getSecureAttribute as jest.Mock).mockReturnValue(true);
27-
(createCookieHandler as jest.Mock).mockImplementation(() => ({
25+
(addYears as ReturnType<typeof vi.fn>).mockReturnValue(mockExpires);
26+
(inCrossOriginIframe as ReturnType<typeof vi.fn>).mockReturnValue(false);
27+
(getSecureAttribute as ReturnType<typeof vi.fn>).mockReturnValue(true);
28+
(createCookieHandler as ReturnType<typeof vi.fn>).mockImplementation(() => ({
2829
set: mockSet,
2930
remove: mockRemove,
3031
get: mockGet,
@@ -52,7 +53,7 @@ describe('createSessionCookie', () => {
5253
});
5354

5455
it('should set cookies with None sameSite in cross-origin context', () => {
55-
(inCrossOriginIframe as jest.Mock).mockReturnValue(true);
56+
(inCrossOriginIframe as ReturnType<typeof vi.fn>).mockReturnValue(true);
5657
const cookieHandler = createSessionCookie(mockCookieSuffix);
5758
cookieHandler.set(mockToken);
5859

packages/clerk-js/src/core/resources/__tests__/Organization.test.ts renamed to packages/clerk-js/src/core/resources/__tests__/Organization.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { Organization } from '../internal';
24

35
describe('Organization', () => {

packages/clerk-js/src/core/resources/__tests__/OrganizationDomain.test.ts renamed to packages/clerk-js/src/core/resources/__tests__/OrganizationDomain.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { OrganizationDomain } from '../internal';
24

35
describe('OrganizationDomain', () => {

packages/clerk-js/src/core/resources/__tests__/OrganizationInvitation.test.ts renamed to packages/clerk-js/src/core/resources/__tests__/OrganizationInvitation.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { OrganizationInvitation } from '../internal';
24

35
describe('OrganizationInvitation', () => {

packages/clerk-js/src/core/resources/__tests__/OrganizationMembership.test.ts renamed to packages/clerk-js/src/core/resources/__tests__/OrganizationMembership.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { OrganizationMembership } from '../internal';
24

35
describe('OrganizationMembership', () => {

packages/clerk-js/src/core/resources/__tests__/OrganizationMembershipRequest.test.ts renamed to packages/clerk-js/src/core/resources/__tests__/OrganizationMembershipRequest.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { OrganizationMembershipRequest } from '../internal';
24

35
describe('OrganizationMembership', () => {

packages/clerk-js/src/core/resources/__tests__/OrganizationSuggestion.test.ts renamed to packages/clerk-js/src/core/resources/__tests__/OrganizationSuggestion.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { OrganizationSuggestion } from '../internal';
24

35
describe('OrganizationSuggestion', () => {

packages/clerk-js/src/core/resources/__tests__/PublicUserData.test.ts renamed to packages/clerk-js/src/core/resources/__tests__/PublicUserData.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { PublicUserData } from '../PublicUserData';
24

35
describe('PublicUserData', () => {

0 commit comments

Comments
 (0)