TheWidlarzGroup / react-native-video

A <Video /> component for react-native
MIT License
7.08k stars 2.85k forks source link

Testing #2654

Open hueniverse opened 2 years ago

hueniverse commented 2 years ago

I have no clue how to write tests for a React Native module like this but I would assume it's possible...

Anyone wants to take a first stab at setting up some tests? Anything at all would be fantastic! I am all ready with a test label!

freeboub commented 2 years ago

Good question ... I don't think jest is very useful ... It is possble to add a string describing player state in JS which describe player state, and then test with appium

freeboub commented 2 years ago

Good question ... I don't think jest is very useful ... It is possble to add a string describing player state in JS which describe player state, and then test with appium

foloinfo commented 1 year ago

I don't think it's possible to test a native module with jest.

However, you can test if the props are passed / changed correctly after mocking the library. jest.mock('react-native-video', ()=> 'ReactNativeVideo').

Only problem is I cannot test the behaviour of ref s like ref.seek. If anyone has a good solution, I would like to know.

talal-tilted commented 10 months ago

Hello did someone find a solution to test it ?

karthik-narayan-v commented 7 months ago

By using this below mock we can test react-native-video:

jest.mock('react-native-video',()=>{
    const React = require('react');
    class Video extends React.Component {
        constructor(props:any){
            super(props);
            this.seek = this.seek.bind(this);
        }
        seek(){}

        render(){
            return React.createElement('Video',this.props,null);
        }
    }
    return Video;
})
freeboub commented 7 months ago

@laughingdevil thank you for this peace of code ! In fact there are 2 topics.