davidjbradshaw / iframe-resizer

Keep iFrames sized to their content.
https://iframe-resizer.com
Other
6.65k stars 981 forks source link

How can I write a test to test what happens when iframeresizer onMessage is invoked? #1173

Closed msarauer closed 11 months ago

msarauer commented 1 year ago

Is there a way to simulate onMessage being invoked in react-testing-library? I've tried:

      const iframe = screen.getByTitle('iframe') as HTMLIFrameElement
      const TEST_MESSAGE = 'test-message'
      iframe.contentWindow?.postMessage(TEST_MESSAGE, window.location.origin)

but that doesn't seem to work.

davidjbradshaw commented 11 months ago

Good question, I think that is more for Stack Overflow