add MessageChannel mock

This commit is contained in:
Ashley Harrison
2025-11-27 11:20:26 +00:00
parent d2bf550499
commit 141ed7bdbf
+16
View File
@@ -126,6 +126,22 @@ global.ResizeObserver = class ResizeObserver {
}
};
global.MessageChannel = jest.fn().mockImplementation(() => {
let onmessage: Function;
return {
port1: {
set onmessage(cb: Function) {
onmessage = cb;
},
},
port2: {
postMessage: (data: unknown) => {
onmessage?.({ data });
},
},
};
});
global.BroadcastChannel = class BroadcastChannel {
onmessage() {}
onmessageerror() {}