I am mocking a function:
jest.mock('utils/downloadData')
In utils/download data I created a mock file:
export default {
general: jest.fn(() => {
console.log('mock fired')
}),
csv: jest.fn(() => {
console.log('mock fired')
}),
}
This function is being called inside a function I am testing:
...
const convertToCsv = () => {
downloadData.csv(CSV.stringify(csvData), fileName)
onFinish()
}
...
When debugging I see that the mock function is correctly set in the closure, when debugging step by step I see that the code reaches inside the mocked function and that console logs the message. Yet this test fails:
expect(downloadData.csv).toBeCalledTimes(1)
Jest accepts downloadData.csv inside the expect so I believe it sees the mocked function.
How is it possible that it doesn't register it as being called?