Sinon stub function used with destructuring

前端 未结 2 1358
我寻月下人不归
我寻月下人不归 2020-12-09 11:54

I wish to stub a function used in the file I\'m currently testing. This function is required with a destructuring like this:

 const { theFunctionIWant } = re         


        
2条回答
  •  天涯浪人
    2020-12-09 12:49

    Since your module returns an object and theMethodIwant is property of that object you can define your stub like this:

    const myModule = require('path/to/module')
    myModule.theMethodIwant = sinon.stub()
    

提交回复
热议问题