I'm facing an issue with my code as I attempt to run a Jest test using ts-jest.
jest.mock('../foo');
import configure from '../configure';
import foo from '../foo';
test('test name', () => {
foo.mockImplementation(() => { methods: {}});
configure();
});
The configure
function utilizes the foo
internally and I aim to mock the foo
function. However, upon running the test, I encounter the error message stating
Property 'mockImplementation' does not exist on type
.
Browsing through other answers on SO, I came across a helpful ts-jest utility named mocked
, which can be leveraged to assert to TS that this is indeed a mock (here and here).
Nevertheless, when I try to implement
import { mocked } from 'ts-jest/utils'
as suggested, I encounter the following error:
Cannot find module 'ts-jest/utils' or its corresponding type declarations.
While exploring the ts-jest documentation, no relevant information was found. In addition, the GitHub documentation for mocked appears to be outdated.
Furthermore, I stumbled upon this resource, suggesting the usage of
as jest.Mocked<typeof foo>;
. Given my utilization of ts-jest, is this the optimal approach?
If anyone could shed some light on how to overcome this challenge, I would greatly appreciate it.