-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.js
42 lines (35 loc) · 1010 Bytes
/
jest.setup.js
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
import '@testing-library/jest-dom';
import base64 from 'base-64';
import fetchMock from 'jest-fetch-mock';
import { setConfig } from 'next/config';
fetchMock.enableMocks();
// eslint-disable-next-line no-console
console.error = jest.fn();
jest.mock('@/layouts/Sidebar.tsx', () => ({
__esModule: true,
Sidebar: () => {
return null;
},
}));
const createToken = () => {
const header = base64.encode(JSON.stringify({ test: 'ok' }));
const payload = base64.encode(
// eslint-disable-next-line no-loss-of-precision
JSON.stringify({ exp: 99999999999999999999999999999999999999999 }),
);
return [header, payload, 'SIGNATURE'].join('.');
};
jest.mock('@/hooks/useCookiesWithOptions.ts', () => ({
__esModule: true,
useCookiesWithOptions: () => ({
cookies: {
token: createToken(),
},
setCookie: jest.fn(),
removeCookie: jest.fn(),
removeAuthenticationCookies: jest.fn(),
}),
}));
setConfig({
publicRuntimeConfig: { apiUrl: 'http://localhost:3000' },
});