forked from deriv-com/bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.ts
43 lines (39 loc) · 1.05 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
import '@testing-library/jest-dom/jest-globals';
import '@testing-library/jest-dom';
let originalLocalStorage: Storage;
const localStorageMock: Storage = {
clear() {
this.store = {};
},
getItem(key) {
return this.store[key];
},
key() {
return 'test key';
},
length: 0,
removeItem(key) {
delete this.store[key];
},
setItem(key, value) {
this.store[key] = value.toString();
},
store: {},
};
export const mockLocalStorageBeforeEachTest = () => {
originalLocalStorage = global.localStorage;
Object.defineProperty(global, 'localStorage', { value: localStorageMock });
};
export const restoreLocalStorageAfterEachTest = () => {
Object.defineProperty(global, 'localStorage', { value: originalLocalStorage });
};
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
})),
});