title: How to mock third-party library custom events with jest and react testing library
body: <p>I am using a third party library 'react-youtube'  which has some methods</p>
  <pre><code>import Youtube from 'react-youtube';
  
  const PlaySection: FunctionComponent&lt;Props&gt; = ({ ytPlayer, setYtPlayer }) =&gt; {
    const [playerState, setPlayerState] = useState&lt;PlayerState&gt;('stopped');
  
    const onClickFn = (state: PlayerState) =&gt; {
       ....
    };
  
    return (
      &lt;div&gt;
        &lt;YoutubeWrapper&gt;
          &lt;Youtube
            videoId={'aasdfasdf'}
            onReady={(e: { target: YT.Player }) =&gt; setYtPlayer(e.target)}
            onStateChange={(e: { data: number }) =&gt; setPlayerState(getPlayerState(e.data))}
          /&gt;
        &lt;/YoutubeWrapper&gt;
        {!!ytPlayer &amp;&amp; (
          &lt;Player
            playerState={playerState}
            onPlay={() =&gt; onClickFn('playing')}
            onPause={() =&gt; onClickFn('paused')}
            onStop={() =&gt; onClickFn('stopped')}
          /&gt;
        )}
      &lt;/div&gt;
    );
  };
  </code></pre>
  <p>How can I mock the 'Youtube' component and make 'onReady' and 'onStateChange' events fire with 'jest' and/or 'React test library'?</p>
  <p>I can imagine creating a mocked Youtube component which would have a button that would trigger 'onReady' when clicking on it. Then I could just use 'fireEvent.click'  but I feel there should be a better way to do that.</p>