Sinon Stub : functions that are called from within another function

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Sinon Stub : functions that are called from within another function



I am trying stub my main function but this function call other function that is inside module.
For example:



MY MODULE


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



The other function always is executed and return false. When , actually, I want to get that other function return true.
Can you help me ?
Thanks









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived