-
Notifications
You must be signed in to change notification settings - Fork 0
/
singleton.ts
37 lines (28 loc) · 894 Bytes
/
singleton.ts
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
import { PrismaClient } from '@prisma/client';
import { ClerkClient } from '@clerk/backend';
import { mockDeep, mockReset, DeepMockProxy } from 'jest-mock-extended';
import prisma from './lib/db';
import clerk from './lib/clerkClient';
import * as clerkServer from '@clerk/nextjs/server';
jest.mock('./lib/db', () => ({
__esModule: true,
default: mockDeep<PrismaClient>(),
}));
beforeEach(() => {
mockReset(prismaMock);
});
export const prismaMock = prisma as unknown as DeepMockProxy<PrismaClient>;
jest.mock('./lib/clerkClient', () => ({
__esModule: true,
default: mockDeep<ClerkClient>(),
}));
beforeEach(() => {
mockReset(clerkMock);
});
export const clerkMock = clerk as unknown as DeepMockProxy<ClerkClient>;
jest.mock('@clerk/nextjs/server');
beforeEach(() => {
(clerkServer.currentUser as jest.Mock).mockReturnValue(
Promise.resolve(global.__USER__)
);
});