I'm trying to write some Jest tests to test if when a function call is made, its inner functions are also invoked. My functions look like this :
fileCoordinator.js
export const save(var1, var2) {
saveToFile(var1,var2)
return var1 + var2
}
export saveToFile(var1, var2){
console.log("saved")
}
My spec file looks like this:
import * fileCoordinator from '../path'
it('should call the inner function', () => {
let spy = jest.spyOn(fileCoordinator, "save")
let spy1 = jest.spyOn(fileCoordinator, "saveToFile")
fileCoordinator.save(1,2)
expect(spy1).toHaveBeenCalled()
})
For some reason, this test fails because the function saveToFile was never called. Any help would be greatly appreciated.