I try to mock the module uuid/v4
coming from npm.
To do that, I have created a mock folder as suggested by jest : https://jestjs.io/docs/en/manual-mocks
My folder structure :
├──__mocks__
| └──uuid
| └──v4.ts
├──src
│ └──__tests__
│ └── ...
├──node_modules
The mock node module file v4.ts :
module.exports = jest.fn();
When I try to import uuid/v4 in my test file, jest should normally import the mock and I should be able to play with it.
Here my test file :
import uuidv4 from 'uuid/v4';
it('should create a job', () => {
const jobId = 'fake-job-id';
uuidv4.mockReturnValue(jobId);
...
}
Unfortunately, the mock import seems not working because I can't add the mockReturnValue
provided by jest and I have the following typescript error :
property 'mockReturnValue' does not exist on type v4. ts(2339)
Do you have any idea how I can fix that please ? Thanks by advance.