Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jasmine 测试简单脚本时出现茶匙错误_Jasmine_Teaspoon - Fatal编程技术网

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);
});