-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsetupTests.js
38 lines (32 loc) · 1.05 KB
/
setupTests.js
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
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
// Mock URL object
global.URL.createObjectURL = jest.fn();
global.URL.revokeObjectURL = jest.fn();
// Mock auto-generated IDs from MUI Material components
jest.mock('@mui/utils/useId', () => jest.fn().mockReturnValue('mui-test-id'));
// Mock local storage
global.localStorage = {
getItem: jest.fn(),
setItem: jest.fn(),
clear: jest.fn(),
};
// Mock console
jest.spyOn(console, 'error').mockImplementation(() => {});
jest.spyOn(console, 'warn').mockImplementation(() => {});
jest.spyOn(console, 'log').mockImplementation(() => {});
// Mock web workers
// Derived from https://github.com/nodejs/help/issues/2058
global.Worker = class Worker {
constructor(stringUrl) {
this.url = stringUrl;
this.onmessage = () => {};
this.addEventListener = () => {};
}
postMessage(msg) {
this.onmessage(msg);
}
};