I am trying to test a function that makes an external call using sinon but I can't figure out how I can muck/stub a function inside it that tries to make an external call.
I hope one of you can give me some insight in this taking the following function as an example.
function Foo (num) {
let externalResult = externalCall(num);
if(externalResult == 15) {
return true;
}
return false;
}
What I would like to stub/moch, is the function externalCall. I would like it to return (for example) 14 every time it is called. I also want to verify that it is called.
I've been searching but have not been able to find anything. I might have overlooked things as all I have is a little background in Java (student). But all I have so far is: it('Should give the right boolean based on the input to the external call.',
async () => {
const testingExService = await ExService.new() // the object to test
});
Aucun commentaire:
Enregistrer un commentaire