I'm trying to mock a dependency of a class I'm importing (note that I'm not trying to mock the imported class!), but I do not how to do it.
Example:
// DependencyIWantToMock.js
class DependencyIWantToMock {
run = async () => {};
}
// ClassIAmTesting.js
class ClassIAmTesting {
run = async () => {
const dependency = new DependencyIWantToMock();
dependency.run();
};
}
// ClassIAmTesting.test.js
import DependencyIWantToMock from './DependencyIWantToMock.js'
jest.mock('./ClassIAmTesting.js')
import ClassIAmTesting from './ClassIAmTesting.js'
test('', async () => {
const instance = new ClassIAmTesting();
await instance.run(); // error -> run is not a funcion (from DependencyIWantToMock)
});
I have been seaerching across the internet but I only find how to mock the imported class, not a dependency of the imported class.
Note: I know, dependency injection, I cannot use that in this case.
Any idea how to get this?