'hooks.MockReturnValue is not a function

So I have created a custom hook

import { useContext } from 'react'
import { angularApiContext } from '../providers/AngularApiProvider'

const useAngularApi = () => {
  const angularApi = useContext(angularApiContext)
  if (angularApi === null) {
    throw new Error('useAngularApi must be called inside of an AngularApiProvider')
  }
  return angularApi
}
export default useAngularApi

And I'm trying to mock it test file like this

import { useAngularApi } from '../../../hooks'
jest.mock('../../../hooks/useAngularApi')

useAngularApi.mockReturnValue({
      $log: {
        warn: jest.fn(),
      },
      CrossFrame: jest.fn(),
      $window: jest.fn(),
    })

But this is failing with _hooks.useAngularApi.mockReturnValue is not a function, any ideas what could be going wrong? I verified the import is right for mock.



Solution 1:[1]

.mock() accepts factory as second parameter so you receive useAngularApi undefined if you omit this.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 standbyoneself