-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.ts
56 lines (47 loc) · 1.25 KB
/
jest.setup.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import '@testing-library/jest-dom';
import { server } from './mocks/server';
import { mockUUID } from './test-utils/mock-uuid';
jest.mock('crypto', () => ({
randomUUID: jest.fn().mockReturnValue(mockUUID),
}));
if (/\*|msw/.test(process.env.DEBUG ?? '')) {
server.events.on('request:start', ({ request }) => {
console.log('Outgoing:', request.method, request.url);
});
server.events.on('response:mocked', ({ request, response }) => {
console.log(
'%s %s received %s %s',
request.method,
request.url,
response.status,
response.statusText,
);
});
}
server.events.on('unhandledException', ({ request, error }) => {
console.log('%s %s errored! See details below.', request.method, request.url);
console.error(error);
});
jest.mock('next-auth', () => {
const originalModule = jest.requireActual('next-auth');
return {
__esModule: true,
...originalModule,
default: jest.fn().mockReturnValue({
auth: jest.fn(),
signIn: jest.fn(),
signOut: jest.fn(),
handlers: {
GET: jest.fn(),
POST: jest.fn(),
},
}),
};
});
beforeAll(() =>
server.listen({
onUnhandledRequest: 'error',
}),
);
afterEach(() => server.resetHandlers());
afterAll(() => server.close());