-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-jest.ts
28 lines (23 loc) · 904 Bytes
/
setup-jest.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
import { TextDecoder } from 'node:util';
import 'jest-preset-angular/setup-jest';
import { ngMocks } from 'ng-mocks';
// Polyfill TextDecoder
global.TextDecoder = TextDecoder as typeof global.TextDecoder;
/**
* Monkey patch console warn and error to fail if a test makes calls to console.warn or console.error.
*/
console.warn = (message?: unknown, ...optionalParams: unknown[]): void => {
const params = optionalParams ? `\nParams: ${String(optionalParams)}` : '';
throw new Error(
`Test contained console warning:\n${String(message)}${params}`,
);
};
console.error = (message?: unknown, ...optionalParams: unknown[]): void => {
const params = optionalParams ? `\nParams: ${String(optionalParams)}` : '';
throw new Error(
`Test contained console error:\n${String(message)}${params}`,
);
};
ngMocks.autoSpy('jest');
// Polyfill needed by MapBoxGL
window.URL.createObjectURL = jest.fn();