I am trying to implement a fetch mock function in my test. Following tutorials I am trying to do this by using jest.fn()
:
const fetchFunction = jest.fn(() => {
return null
})
This does not work for some reason.
If I just do console.log(fetchFunction)
in my test I get:
[Function: mockConstructor] {
_isMockFunction: true,
getMockImplementation: [Function],
mock: [Getter/Setter],
mockClear: [Function],
mockReset: [Function],
mockRestore: [Function],
mockReturnValueOnce: [Function],
mockResolvedValueOnce: [Function],
mockRejectedValueOnce: [Function],
mockReturnValue: [Function],
mockResolvedValue: [Function],
mockRejectedValue: [Function],
mockImplementationOnce: [Function],
mockImplementation: [Function],
mockReturnThis: [Function],
mockName: [Function],
getMockName: [Function]
}
However if I try to invoke it by console.log(fetchFunction())
I get undefined
?
I am trying this to do in a create-react-app folder. Do I have to install something extra? Any ideas about why this happens?