Javascript Jest:提供的元素或ID无效。(视频JS)
当运行jest覆盖率测试时,我不断得到Javascript Jest:提供的元素或ID无效。(视频JS),javascript,jestjs,Javascript,Jestjs,当运行jest覆盖率测试时,我不断得到元素或提供的ID无效。(videojs)指向我的JS行:this.player=videojs(this.videoPlayerID,this.videoJSConfig)。我不确定我在测试中做了什么不正确,或者我没有提供什么 js 试验 import videojs from 'video.js'; class IVSPlayer { constructor(data) { this.player = {}; this.registe
元素或提供的ID无效。(videojs)
指向我的JS行:this.player=videojs(this.videoPlayerID,this.videoJSConfig)代码>。我不确定我在测试中做了什么不正确,或者我没有提供什么
js
试验
import videojs from 'video.js';
class IVSPlayer {
constructor(data) {
this.player = {};
this.registerIVSTech = data.ivsTech;
this.videoPlayerID = data.id;
this.videoJSConfig = data.config;
}
init() {
this.registerIVSTech(videojs);
this.videoJSConfig.techOrder = ['AmazonIVS'];
this.player = videojs(this.videoPlayerID, this.videoJSConfig);
return this.player;
}
}
export default IVSPlayer;
/**
* @jest-environment jsdom
*/
import ivsPlayer from './../../../ivs-player';
import { VIDEO_PLAYER_ID } from '../../../asset-constants';
import { VIDEO_JS_CONFIG } from './../../../create-player';
import videojs from './../../../node_modules/video.js';
describe('#ivsPlayer', () => {
it('creates an instance of the IVS player', () => {
const registerIVSTech = jest.fn();
const player = new ivsPlayer({ id: VIDEO_PLAYER_ID, config: VIDEO_JS_CONFIG, ivsTech: registerIVSTech });
expect(player).toBeTruthy();
});
it('initializes the IVS player', () => {
jest.spyOn(ivsPlayer.prototype, 'init');
const registerIVSTech = jest.fn();
const player = new ivsPlayer({ id: VIDEO_PLAYER_ID, config: VIDEO_JS_CONFIG, ivsTech: registerIVSTech });
player.init();
player.videoJSConfig.techOrder = jest.fn().mockReturnValue(['AmazonIVS']);
player.registerIVSTech = jest.fn().mockReturnValue(player);
expect(player.init).toHaveBeenCalledTimes(1);
});
});