-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup-jest.ts
More file actions
31 lines (27 loc) · 943 Bytes
/
setup-jest.ts
File metadata and controls
31 lines (27 loc) · 943 Bytes
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
import { setupZoneTestEnv } from "jest-preset-angular/setup-env/zone";
setupZoneTestEnv();
// Mock scrollIntoView which is not implemented in jsdom
Element.prototype.scrollIntoView = jest.fn();
// Mock window.matchMedia which is not implemented in jsdom
Object.defineProperty(window, "matchMedia", {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
// Suppress CSS parsing errors from jsdom (it doesn't support all modern CSS features)
const originalConsoleError = console.error;
console.error = (...args: unknown[]) => {
const message = args[0]?.toString() ?? "";
if (message.includes("Could not parse CSS stylesheet")) {
return;
}
originalConsoleError.apply(console, args);
};