cookpete / react-player

A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion
https://cookpete.github.io/react-player
MIT License
8.94k stars 1.12k forks source link

How to mock the tests for react Player? #1694

Closed Harsh6637 closed 1 month ago

Harsh6637 commented 7 months ago

There should be an example in the /example dir of how to mock the React Player for tests.

I have a component MyComponent which uses the React Player. When i render the Mycomponent in my test case i am unable to get instance of the player due to which i am unable to write the tc for the same. Any docs or resource would be great for this.

<ReactPlayer data-testid={video-player-${media.id}} ref={(player) => ref(player, index)} className={${styles["react-player"]}} width="100%" height="100%" url={media.url} controls={true} pip={false} playing={(function () { if (index === 0) { return true } else return false }())} config={{ youtube: { playerVars: { showinfo: 1, disablekb: 0, enablejsapi: 1, modestbranding: 1, rel: 0, fs: 0, iv_load_policy: 3, playsinline: 1 } } }} playsinline={true} onStart={() => handleOnStart(index)} onPlay={() => handleOnStart(index)} onPause={() => handleOnMediaPause()} onEnded={() => handleOnMediaPause()} onError={() => handleOnError()} />