Jasmine 测试简单脚本时出现茶匙错误
我正在测试以下代码逻辑:Jasmine 测试简单脚本时出现茶匙错误,jasmine,teaspoon,Jasmine,Teaspoon,我正在测试以下代码逻辑: handleOnMediaPlaying: function(event){ // body... if(isAd){ if(event.data.percentComplete >= 25 && !firstQuartileFlag){ firstQuartileFlag = true; } if(event.data.percentComplete >= 50 && !midpo
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(如果媒体是ad)、firstQuartileFlag(设置为false)、midpointflag(设置为false)和thirdQuartileFlag(设置为false)。
我已经为相同的代码编写了以下规范,但它失败了,错误是“expected false to true”。以下是规格
描述(“掌上游戏”,函数(){
}))
我不知道当一切都是直截了当的时候它为什么会失败。请帮忙。我解决了问题,间谍(pdkHandler,'handleOnMediaPlaying');方法保留函数handleOnMediaPlaying的执行,因此该值未设置为预期的true。 希望这能帮助像我这样的新手
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);
});