预期的间谍点击已被调用

时间:2019-10-29 16:36:10

标签: javascript jquery jasmine teaspoon

我正在测试在Jasmine-Teaspoon中调用元素的click事件。但是,我得到一个错误:

  

“预期会发生间谍点击。”

const search = window.location.search;
const params = new URLSearchParams(search);
const foo = params.get('bar');

在此处查看正在测试的完整代码:

ReferenceError: Can't find variable: onPlayerReady (When using callback)

1 个答案:

答案 0 :(得分:0)

请参考链接的问题的上下文:

onPlayerStateChange(event) {
 if(event.data === 0) {           
   $('.close.close-popup').click();
 }
}

event.data是否设置为0?因为undefined不等于0:false ===(undefined === 0)

describe('onPlayerStateChange', () => {
    it('should stop video when data equals to zero', () => {
        event.data = 0;
        const closeElmeent = $(".close.close-popup");
        const spy = spyOn(closeElmeent, 'click'); // if you want it to actually click, you can use "spyOn(closeElmeent, 'click').and.callThrough();"
        onplayerStateChange(event);
        expect(spy).toHaveBeenCalled();
    });
});