【发布时间】:2015-12-11 00:14:35
【问题描述】:
我正在测试以下代码逻辑:
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)。 我已经为相同的内容编写了以下规范,但它失败并出现错误说“预计错误为真”。以下是规格....
describe("handleOnMediaPlaying", function(){
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);
});
});
我不知道为什么当一切都直截了当时它会失败。请帮忙。
【问题讨论】: