forked from react/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatchMessageChannel.js
More file actions
30 lines (27 loc) · 908 Bytes
/
Copy pathpatchMessageChannel.js
File metadata and controls
30 lines (27 loc) · 908 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
'use strict';
export function patchMessageChannel(Scheduler) {
global.MessageChannel = class {
constructor() {
const port1 = {
onmesssage: () => {},
};
this.port1 = port1;
this.port2 = {
postMessage(msg) {
if (Scheduler) {
Scheduler.unstable_scheduleCallback(
Scheduler.unstable_NormalPriority,
() => {
port1.onmessage(msg);
}
);
} else {
throw new Error(
'MessageChannel patch was used without providing a Scheduler implementation. This is useful for tests that require this class to exist but are not actually utilizing the MessageChannel class. However it appears some test is trying to use this class so you should pass a Scheduler implemenation to the patch method'
);
}
},
};
}
};
}