Posts

Showing posts with the label stub

Sinon Stub : functions that are called from within another function

Image
Clash 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 ...