-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjestSetup.ts
More file actions
38 lines (29 loc) · 832 Bytes
/
jestSetup.ts
File metadata and controls
38 lines (29 loc) · 832 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
import { Worker } from 'node:worker_threads';
import { URL_MOCK, BLOB_MOCK, WINDOW_MOCK } from './@tests/fixtures';
export class WORKER_MOCK extends Worker {
constructor(source: string) {
super(source);
this.addListener('message', (message) => {
this.onmessage?.(message);
});
}
public postMessage(data: any, transfer?: any[]) {
const event = {
data,
};
super.postMessage(event, transfer);
}
public onmessage: (event: { data: any }) => void = () => {};
public onerror: (event: { data: any }) => void = () => {};
}
beforeEach(() => {
const globalAny: any = global;
globalAny.window = WINDOW_MOCK;
globalAny.Blob = BLOB_MOCK;
globalAny.window.URL = URL_MOCK;
globalAny.Worker = WORKER_MOCK;
});
afterEach(() => {
jest.restoreAllMocks();
jest.clearAllMocks();
});