forked from transcend-io/consent-manager-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.ts
29 lines (22 loc) · 902 Bytes
/
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
/* eslint-disable @typescript-eslint/no-explicit-any */
import { jest } from '@jest/globals';
import { readFileSync } from 'fs';
import { airgapStub } from './src/playground/airgapStub';
import { testWindow } from './src/tests/utils/render'
testWindow.JEST_SETUP_VARS = { messages: {} };
const MESSAGES_PATH = 'src/translations/en.json';
const messagesStringified = readFileSync(MESSAGES_PATH, 'utf8');
const messages = JSON.parse(messagesStringified);
testWindow.JEST_SETUP_VARS.messages = messages;
(testWindow as any).fetch = jest.fn().mockImplementation((path: any) => {
const data = readFileSync(path, 'utf8');
return Promise.resolve({
ok: true,
json: () => JSON.parse(data),
});
});
/**
* Add Airgap API stub to window/self/globalThis
*/
(testWindow as any).airgap = Object.assign(airgapStub, (window as any).airgap);
/* eslint-enable @typescript-eslint/no-explicit-any */