-
Notifications
You must be signed in to change notification settings - Fork 405
/
setup-jest-preset.ts
53 lines (44 loc) · 1.04 KB
/
setup-jest-preset.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
import { TextDecoder, TextEncoder } from 'node:util';
Object.assign(global, { TextDecoder, TextEncoder });
import 'jest-preset-angular/setup-jest';
const CI = process.env['CI'] === 'true';
/**
* GLOBAL MOCKS
*/
Object.defineProperty(window, 'CSS', { value: null });
Object.defineProperty(document, 'doctype', {
value: '<!DOCTYPE html>'
});
Object.defineProperty(window, 'getComputedStyle', {
value: () => {
return {
display: 'none',
appearance: ['-webkit-appearance']
};
}
});
/**
* ISSUE: https://github.com/angular/material2/issues/7101
* Workaround for JS DOM missing transform property
*/
Object.defineProperty(document.body.style, 'transform', {
value: () => {
return {
enumerable: true,
configurable: true
};
}
});
if (CI) {
const consoleMethods: string[] = [
'trace',
'debug',
'warn',
'log',
'group',
'groupCollapsed'
];
consoleMethods.forEach((methodName: string) => {
jest.spyOn(global.console, methodName as any).mockImplementation(() => jest.fn());
});
}