0
我測試下面的代碼邏輯:茶匙錯誤而測試簡單的腳本
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內部。此外,還有另一個函數handleOnMediaStart在pdhHandler中,我定義變量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);
});
});
我不知道爲什麼當一切都很簡單時它失敗了。請幫忙。