-
Notifications
You must be signed in to change notification settings - Fork 22
/
jest-global-mocks.ts
52 lines (45 loc) · 1.29 KB
/
jest-global-mocks.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
/* global mocks for jsdom */
// eslint-disable-next-line no-null/no-null
Object.defineProperty(window, 'CSS', {value: null});
Object.defineProperty(document, 'doctype', {
value: '<!DOCTYPE html>'
});
Object.defineProperty(window, 'getComputedStyle', {
value: () => ({
display: 'none',
appearance: ['-webkit-appearance']
})
});
/**
* ISSUE: https://github.com/angular/material2/issues/7101
* Workaround for JSDOM missing transform property
*/
Object.defineProperty(document.body.style, 'transform', {
value: () => ({
enumerable: true,
configurable: true
})
});
const mock = () => {
const storage = new Map<string, any>();
return {
getItem: (key: string) => storage.get(key),
setItem: (key: string, value: string) => storage.set(key, value || ''),
removeItem: (key: string) => storage.delete(key),
clear: () => (storage.clear())
};
};
Object.defineProperty(window, 'localStorage', {value: mock()});
Object.defineProperty(window, 'sessionStorage', {value: mock()});
jest.mock('./src/app/worker/create-stats-solve.worker.ts', () => ({
createStatsSolveWorker: () => {
// nope
}
}));
jest.mock('./src/app/worker/create-solve.worker.ts', () => ({
createSolveWorker: () => {
// mope
}
}));
/* output shorter and more meaningful Zone error stack traces */
// Error.stackTraceLimit = 2;