TypeScript doesn't recognize my jest mock module
Since typescript is not aware of jest
mocking, you will need to manually type cast whenever your mocks are different than your actual code:
import * as MockDatabase from "../__mocks__/Database";
import * as Database from "../Database";
import { runSomeQuery } from "../index";
jest.mock("../Database");
// Type cast since Database is automatically mocked by jest
const { connect, __getMockConnection } = Database as typeof MockDatabase;
test("runSomeQuery", async () => {
await runSomeQuery();
const mockConnection = __getMockConnection();
expect(connect).toBeCalled();
expect(mockConnection.query).toBeCalledWith("SOME QUERY");
});