Sinon function stubbing: How to call “own” function inside module

后端 未结 1 1929
天命终不由人
天命终不由人 2020-12-10 15:42

I am writing some unit tests for node.js code and I use Sinon to stub function calls via

var myFunction = sinon.stub(nodeModule, \'myFunction\');
myFunction.         


        
相关标签:
1条回答
  • 2020-12-10 16:45

    You can refactor your module a little. Like this.

    var service = {
       myFunction: myFunction,
       anotherFunction: anotherFunction
    }
    
    module.expors = service;
    
    function myFunction(){};
    
    function anotherFunction() {
       service.myFunction(); //calls whatever there is right now
    }
    
    0 讨论(0)
提交回复
热议问题