I am writing tests for functions in a file. Several functions call another function which is also in that file. Here is how it looks:
function importantFunc(str) {
//some logic
return result;
}
function funcA() {
//some logic
const result = importantFunc('test A')
//some logic
}
function funcB() {
//some logic
const result = importantFunc('test B')
//some logic
}
I have already written a test for importantFunc
. Problem is how can I test mock the call to importantFunc
in funcA
and funcB
so that they will not call importantFunc
directly, but use the result I provide in my mock?
Between jest.spyOn
and jest.fn
, I am thinking jest.fn
may work. But I cannot figure out how it will tie to funcA
or funcB
.