繁体   English   中英

Sinon存根在这种情况下不起作用?

[英]Sinon stub is not working in this scenario?

我正在尝试使用sinon存根通过创建IF语句的模拟值来测试我的功能,如testFunction中所述

在文件myFunction.js之一中,我具有如下功能

function testFunction() {
  var job = this.win.get.value1   //test
  var job1 = this.win.get.value2 // test1
  if(job === 'test' && job1 === 'test1') {
    return true;
  }
    return false; 
}

我正在尝试使用业力测试testFunction,并且试图使用sinon stub来测试功能

it('should test my function', function(done) {
  var stub = sinon.stub(myFunction,'job','job1').returns('test','test1');
  myFunction.testFunction('test', function(err, decodedPayload) {
    decodedPayload.should.equal(true);
    done();
  });
});

有人可以告诉我我在哪里做错吗?

您使用的sinon.stub错误。 您需要对sinon.stub进行两次调用,对于要存根的myFunction每个方法sinon.stub一次调用。

it('should test my function', function(done) {
  sinon.stub(myFunction,'job').returns('test');
  sinon.stub(myFunction,'job1').returns('test1');
  myFunction.testFunction('test', function(err, decodedPayload) {
    decodedPayload.should.equal(true);
    done();
  });
});

请参阅Sinon文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM