When I import a mocked function, Typescript doesn't recognize that Jest changes the import to a mock. As a result, I have to cast the imported function in order to utilize mock methods such as mockReturnValue
.
jest.mock('../myImport');
import { thisFunctionIsMocked } from '../myImport'
/* ... */
(<Mock<any>>thisFunctionIsMocked).mockReturnValue(42);
If I don't cast the import, Typescript gives an error claiming that the mock function methods do not exist. Is there a more efficient way to handle this situation?