我想测试“视频”组件是否正确加载了视频。我为“视频”组件创建了“ videoStream”参考:
<video ref={videoStream} width="100%" preload="auto">
<source src={this.props.video_source} type={this.props.file_type}/>
</video>
在我的videoPlayer.test.js中:
wrapper = mount(<VideoPlayer video_source={"/video_samples/video.mp4"} file_type={"video/mp4"}/>);
describe('Video player', () => {
it('should correctly load video', async () => {
jest.useFakeTimers();
setTimeout(() => {
expect(wrapper.instance().videoStream.current).toBeDefined();
expect(wrapper.instance().videoStream.current.duration).toBeGreaterThan(0);
}, 4500);
jest.runAllTimers();
});
}
/ video_samples / video.mp4存储在公用文件夹中。
[以'npm start'启动项目时,视频正确加载且持续时间为15。但是当我执行'npm test'时,持续时间始终为0。它应大于0。
我猜是将源传递给VideoPlayer的问题。帮我解决这个问题。