I am using Jest to mock the fs.promises.readDir function.
At first I created a mock with ts-jest and then tried to set up the mock as follows:
import fs from 'fs';
jest.mock('fs');
const mockFs = mocked(fs, true);
describe(..., () => {
it(..., () => {
mockFs.promises.readdir.mockResolvedValue(['a.txt']);
});
});
The problem that I am facing with is that TypeScript can not find the proper overload which returns a promise of a string[] but the one that returns a promise of a Dirent[].
Moreover it also says that mockFs.promises is undefined.
How can I make it work and mock the right function?