Let's say I have a super simplified utility class, utilities.ts:
export const one = (someParam: Object) => {
// some logic
}
export const two = (someArr: Object[]) => {
const modifiedValues = [];
for(const i of someArr) {
modifiedValues.push(one(i));
}
return modifiedValues;
}
I want to test that two()
calls one()
3 times when someArr
has length 3. I don't care to test what one()
is doing because I'm testing that elsewhere. I'm not able to get jest.spyOn
to work as I would expect. Per other discussions I've tried:
import * as utils from '../utils';
// inside test block
const oneSpy = jest.spyOn(utils, 'one').mockImplementation(); // tried without mockImplementation as well
const result = utils.two( /* some test array of length 3 */);
expect(oneSpy).toHaveBeenCalledTimes(3);
and am getting a failure that is has received 0 calls. I don't want to do jest.mock
because I do want to test the actual functionality, just not in this particular test.
What am I missing here?