0

I have implemented cross-browser tab communication using the broadcast channel API in my React Project. It's working as expected in the browser, but I am struggling to write unit tests for it using JEST. When I run the test case, the post message gets called, but the onmessage function never gets called. Can anyone help me?

const channel = new BroadcastChannel('some-name');

channel.onmessage = function(e) {
  // some code

}

 channel.postMessage({ message: 'some message' });
Asif Iqbal
  • 502
  • 6
  • 24
  • Hi Asif Iqbal, I have not yet found how to resolve this and am experiencing the exact same issue. I have so far tried installing broadcast-channel npm and mocking the polyfill neither fire the listener. It is very frustrating. – ServerStorm May 30 '23 at 14:04

0 Answers0