forked from webex/webex-js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest-preload.js
More file actions
39 lines (31 loc) · 933 Bytes
/
jest-preload.js
File metadata and controls
39 lines (31 loc) · 933 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
32
33
34
35
36
37
38
39
/* To debug something while using jest , use console.debug() as this is not mocked */
global.console = {
...console,
log: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
trace: jest.fn(),
};
global.Worker = class {
onmessage = jest.fn();
onerror = jest.fn();
postMessage() {}
terminate() {}
};
const OriginalURL = global.URL || URL;
global.URL = jest.fn().mockImplementation((url, base) => {
// Use the actual URL constructor for normal URL operations
return new OriginalURL(url, base);
});
// Add the static methods you need for blob handling
global.URL.createObjectURL = jest.fn(() => 'mocked-blob-url');
global.URL.revokeObjectURL = jest.fn();
global.Blob = class {
constructor(content, options) {
this.content = content;
this.options = options;
this.size = content ? content.reduce((acc, item) => acc + item.length, 0) : 0;
this.type = options?.type || '';
}
};