mocking 'react-player' default methods in tests

213 views Asked by At

ReactPlayer comes with the default methods for onStart, onPlay, onEnd functions. While trying to write the tests, it is not covered which reduces the codecoverage.

Similar to: I am using a third party library 'react-player' which has some methods

am new to testing.I am trying to test the play, pause functionaltiy of ReactPlayer of react-player package. How can I mock the 'ReactPlayer' component and can access events and instances with 'jest' and/or 'React test library'?

1

There are 1 answers

0
Mister_CK On

You don't have to unit test a library that has unit tests of it's own. You are talking about code coverage, so I suspect that you want to test your own code that uses the functions from React-Player. Could you share that code? both the component and the test that you have written so far?

You probably want to mock the module with something like:

jest.mock(
  'react-player',
  () => {
     return {
       open: jest.fn(),
       onPlay: jest.fn(),
       onEnd: jest.fn()
     };
  },
);