Sinon Stub:从另一个函数中调用的函数

时间:2018-07-31 08:48:49

标签: node.js sinon stub

我正在尝试对我的主要函数进行存根处理,但是此函数调用模块内部的其他函数。 例如:

我的模块

module.exports = {
      main,
      other
    }
    function main(val) {
      if(other(val)) {
        return 'OK'
      } else {
        return 'KO'
      }
    }

    function other(val) {
      return x>1
    }

TEST.SPEC

const sinon = require('sinon')
describe(('Test My Module'), () => {
  it('I want to get KO', () => {
    const myModule = require('myModule')
    const stubOther = sinon.stub(myModule, 'other')
    stubOther.withArgs(0).returns(true)
    console.log(myModule.main(0))
  })
})

总是执行另一个函数,并返回false。实际上,当我想让其他函数返回true时。 你能帮助我吗 ? 谢谢

0 个答案:

没有答案
相关问题