我正在测试以下代码逻辑:
handleOnMediaPlaying: function(event){
// body...
if(isAd){
if(event.data.percentComplete >= 25 && !firstQuartileFlag){
firstQuartileFlag = true;
}
if(event.data.percentComplete >= 50 && !midpointflag){
midpointflag = true;
}
if(event.data.percentComplete >= 75 && !thirdQuartileFlag){
thirdQuartileFlag = true;
}
}
},
函数“handleOnMediaPlaying”在对象 pdkHandler 内。此外,在 pdhHandler 中还有另一个函数 handleOnMediaStart,我在其中定义变量 isAd(如果媒体是广告)、firstQuartileFlag(设置为 false)、midpointflag(设置为 false)和 thirdQuartileFlag(设置为 false)。我已经为相同的内容编写了以下规范,但它失败并出现错误说“预计错误为真”。下面是规格......
描述(“handleOnMediaPlaying”,函数(){
beforeEach(function(){
isAd = true;
firstQuartileFlag = false;
midpointflag = false;
thirdQuartileFlag = false;
spyOn(pdkHandler, 'handleOnMediaPlaying');
});
it('sets firstQuartileFlag to true on percentComplete = 26 ', function(){
var eventAd = {
data: {
percentComplete: 26
}
};
pdkHandler.handleOnMediaPlaying(eventAd);
expect(firstQuartileFlag).toBe(true);
});
it('sets midpointflag to true ', function(){
var eventAd = {
data: {
percentComplete: 50
}
};
pdkHandler.handleOnMediaPlaying(eventAd);
expect(midpointflag).toBe(true);
});
it('sets thirdQuartileFlag to true ', function(){
var eventAd = {
data: {
percentComplete: 76
}
};
pdkHandler.handleOnMediaPlaying(eventAd);
expect(thirdQuartileFlag).toBe(true);
});
});
当一切都直截了当时,我不知道为什么它会失败。请帮忙。